【发布时间】:2010-08-23 16:05:52
【问题描述】:
在归档时我卡在这里。while 循环的条件不起作用。编译器说无法将 int 转换为 FILE*。
while(pFile!=EOF);
我应该将 pFile 类型化为 int 吗?我试过了,但没有成功。提前致谢。 完整代码为:
int main()
{
char ch;
char name[20];
FILE *pFile;
int score;
pFile=fopen("database.txt","r");
if(pFile!=NULL)
{
while(pFile!=EOF);
{
fscanf(pFile,"%c",ch);
}
}
else
printf("Cant open the file.......");
fclose(pFile);
return 0;
}
【问题讨论】:
-
建议:代替 printf("Can't open the file...." ),试试 perror(name); (在以前的某个时间点,您已经将“database.txt”复制到名称中,并且您已经处理了缓冲区大小问题。)这会将错误消息放在正确的流上,并且会提供更多信息。 perror 是你的朋友。
-
在输出中它会打印错误但也会打印 ERROR=0,那是什么?