Hack Forums
[C] struct incorrect? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [C] struct incorrect? (/showthread.php?tid=5395839)



[C] struct incorrect? - Annabelle Lee - Sep 4, 2016

I mean you have a few spelling errors mostly... that's one issue. A few others:

Here is a working code. You can delete the for loop, but it shows that you have 7 structs in the array.

Code
#include <stdio.h>
#define N 7
typedef struct
{
    char name [26];
    int score;

} Player;

int main (int argc, char* argv[] ){

    Player players[N];
    printf("Hello world!\n");
    int i;
    for(i = 0; i < N; i++){
        players[N].score = i+1;
        printf("Player %d is made.\n", i+1);
    }
    return 0;
}



* - Sakuto - Sep 5, 2016

There is a section for C related question, post your thread on it.