Hi
I have the following struct:
Then I fill it:Code:struct player{ char *name; // Name int score; // Current score int bonus; // Number of bonuses(ekstratur) };
Now I try to get the name of one of the players:Code:int i = 1; // Loop counter var char *name = NULL; int main(void) { printf("Indtast antallet af spillere: "); scanf("%d",&players); typedef struct player player; player play[players]; for(i = 1; i<=players; i++){ printf("Indtast spiller %d's navn: ",i); // Prompt for name scanf("%s",&name); // Write name play[i].name = name; // Store name in player play[i].score = 0; // Write score (reset) play[i].bonus = 0; // Write bonus (reset) } // End for
The printed string is blank.....can someone see the error?Code:printf("%s",play[0].name);




Reply With Quote