C语言怎样读取文本的每一行?
1个回答
展开全部
FILE *fin;
char *one_line;
one_line = (char*)malloc( MAX_LINE_SIZE * sizeof(char) );
if((fin = fopen(argv[1], "r"))==NULL)
{
printf("can not open file %s !\n", argv[1]);
exit(-1);
}
while( fgets(one_line, MAX_LINE_SIZE, fin) != NULL )
{
printf("读一行打印一行%s",one_line);
}
fclose(fin);
char *one_line;
one_line = (char*)malloc( MAX_LINE_SIZE * sizeof(char) );
if((fin = fopen(argv[1], "r"))==NULL)
{
printf("can not open file %s !\n", argv[1]);
exit(-1);
}
while( fgets(one_line, MAX_LINE_SIZE, fin) != NULL )
{
printf("读一行打印一行%s",one_line);
}
fclose(fin);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询