文件问题,大家给找一下错误
程序代码:#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char filename[20]={'\0'},buff;
int line=1;
FILE *fp;
puts("please input the file directory");
scanf("%s",filename);
if(fp=fopen(filename,"r")==NULL)
{printf("cannot open the file!\n");
exit (0);
}
printf("open file OK \n%d",line);
buff=fgetc(fp);
while(buff !=EOF)
{ printf("while is OK");
if(buff=='\n')
{line++;
printf("\n%d",line);
}
else putchar(buff);
buff=fgetc(fp);
}
fclose(fp);
return 0;
}
目的是显示一个文件并在开头显示行数。
但是运行就是不行。open File OK都能显示,往后就没了。
不知道是什么问题~大家给看一下~








