Array Konstruktion mit etlichen Errors



  • ich habe hier mal eine array Konstruktion gemacht.

    // Variablen
    short int spieler1[4]={1,2,3,4}, spieler2[4]={5,6,7,8}, spieler3[4]={9,10,11,12}, spieler4[4]={13,14,15,16};
    short int spieler[4] = {spieler1,spieler2,spieler3,spieler4};
    

    Die macht jedoch den Fehler:

    main.c:67: warning: initialization makes integer from pointer without a cast
    main.c:67: error: initializer element is not computable at load time
    main.c:67: error: (near initialization for 'spieler[0]')
    main.c:67: warning: initialization makes integer from pointer without a cast
    main.c:67: error: initializer element is not computable at load time
    main.c:67: error: (near initialization for 'spieler[1]')
    main.c:67: warning: initialization makes integer from pointer without a cast
    main.c:67: error: initializer element is not computable at load time
    main.c:67: error: (near initialization for 'spieler[2]')
    main.c:67: warning: initialization makes integer from pointer without a cast
    main.c:67: error: initializer element is not computable at load time
    main.c:67: error: (near initialization for 'spieler[3]')

    und wenn ich das oben definierte verwenden will:

    for (i=1; i<=player ; i++)
    {   
    for (a=1; a<=4 ; a++)
    	{
    		pos = spieler[i][a];
            }
    }
    

    kommt

    main.c:111: error: subscripted value is neither array nor pointer

    woran liegts 😕



  • short int* spieler[4] = {spieler1,spieler2,spieler3,spieler4};
    


  • Von welchem Typ sind denn spieler1 , spieler2 , spieler3 und spieler4 , die du versuchst in ein short int -Array zu quetschen?

    greetz, Swordfish

    BTW: Arrays beginnen in C bei 0 .



  • die sind auch von short int

    @ agga ugga, thx, das hat geklappt



  • floorball92 schrieb:

    die sind auch von short int

    Quatsch mit Soße. Die sind short int[ ] was fast das selbe ist wie short int * . Deswegen regt sich auch Dein Compiler auf. Denk' mal darüber nach... So nach dem Motto: "Es funktioniert plötzlich, und ich verstehe auch, warum." 🙄

    greetz, Swordfish



  • for (i=1; i<=player ; i++) 
    {   
    for (a=1; a<=4 ; a++) 
        { 
            pos = spieler[i][a]; 
            } 
    }
    

    Man fängt bei 0 an zu zählen.


Anmelden zum Antworten