这个程序工作,
它逐行读取一个大日志文件,读取3行后,它显示segmentation fault。
int main(int argc, char *argv[])
{
char *line;
FILE *my_stream;
char *my_filename = "log";
my_stream = fopen (my_filename, "r");
while(fscanf (my_stream, "%s", &line)!= EOF)
{
printf ("==> %s\n", &line);
}
fclose (my_stream);
return 0;
}
输出
==> 123 ==> 12345 ==> 1234568 Segmentation fault