test.c
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
char *file[256];
int line = 0;
if(argc == 2) {
FILE *fp;
fp = fopen(argv[1],"r");
while(fgets(file[line],81,fp) != NULL){
printf("file[%d] is [%s]\n",line,file[line]);
line++;
}
fclose(fp);
return 0;
} else {
printf("ERROR\n");
return 1;
}
}
If I run it after compile,
>./a.out result.txt
file[0] is [2]
file[1] is [korea]
file[2] is [united States]
file[3] is [3,2]
above this is supposed to be result, but it said
segmentation fault after print out file[0] is [2]
result.txt is like this..
2
korea
united States
3,2
plz ..help..me..
[code][/code]tagged by Salem