我试图一次从一个文件中读取一个字节:
size_t result_new = 1;
char buf6[1];
if( (result_new = fread(buf6, 1, 1, pFile)) != 1)
{
printf("result_new = %d\n", result_new);
printf("Error reading file\n");
exit(1);
}
result_new
变为 0 并打印错误。任何想法可能是错的。我确定 pFile
没问题。
谢谢
最佳答案
根据文档:
fread() and fwrite() return the number of items successfully read or written (i.e., not the number of characters). If an error occurs, or the end-of-file is reached, the return value is a short item count (or zero).
那么,您为什么不检查能够回答您的问题的错误代码呢?您可以使用 perror
,例如。
关于c - 恐惧的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4830694/