Hi..I got stuck with file handling..
how can I get the each line's string from the file..??
I mean..for example, if I have file which contain
2--->how many countries participate
canada
united states
2,1-->these are score for the game
then, how can I store each line into array??
like ["2","canada","united states", "2,1"]
the file format always like that, but I should handle 2 team to 256 teams..so..anyway..anybody knows how to handle the file like this??
Here is my code....
Code:
#include<stdio.h>
int main(int argc, char *argv[]){
char *file[512];
int line = 0;
if (argc == 2){
FILE *fp;
fp = fopen(argv[1], "r");
while (fgets(file[line], 81, fp) != 0){
printf("file[%d] is [%s] \n", line, file[line]);
line++;
}
fclose(fp);
return (0);
}else {
printf("theres no input file\n");
return (-1);
}
}
[code][/code]tagged by Salem