虽然做文件im卡在这里。while循环的条件不工作。编译器说不能将int转换为FILE *。编译器说:不能将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(“无法打开文件....”),请尝试perror(name); (在某些情况下,您之前已经将“database.txt”复制到名称中,并且已经处理了缓冲区大小问题)。这会将错误消息放在适当的流中,并且它会提供更多信息。 perror是你的朋友。 – 2010-08-23 16:23:33
@William:谢谢:) – 2010-08-23 16:29:09
在输出中打印错误,但打印ERROR = 0,那是什么? – 2010-08-23 16:34:12