Hi, anyone knows why my code is giving me a 'fatal error'? I have already put my data file data.txt in the correct directory so it should not be the problem....:undecided Code: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> struct type_player { char name1[20], name2[20]; int scoring_ability1, scoring_ability2, valid; }; // function prototypes void read( struct type_player player[], int *N ); int main() { struct type_player player[100]; int N; read( player, &N ); //check( player, N ); //best( player, N); return 0; } //implement function 'read' void read( struct type_player player[], int *N ) { int number=0, i; FILE *fp = fopen( "data.txt", "r" ); if( fp==NULL ) printf( "Unable to open the file"); else { fscanf( fp, "%d", &number); *N=number; for( i=0; i<number; i++ ) { fscanf( fp, "%s %s %d %d", &player[i].name1, &player[i].name2, &player[i].scoring_ability1, &player[i].scoring_ability2 ); } } fclose( fp ); }
player.name1 is already the address of where you want the data to go, so you don't need to take its address again. If that doesn't fix it, what are the contents of data.txt?
The contents of data.txt are as follow: PS:I have tried to remove the & but there is still fatal error 7 pele polo 93 94 maradona maradoni 93 94 vanbasten vanboston 92 93 shearer shaeror 91 93 gullit glulit 89 94 shevchenko shevchinko 80 75 cronaldo crinaldo 90 99
OOps, I think I made a mistake right from the start, I created the wrong project...sorry for all the trouble....