为什么我得到:
fread() failed
我在 VS 2010 中运行这段代码
#include<stdio.h>
#include<string.h>
#define SIZE 1
#define NUMELEM 5
int main(void)
{
FILE* fd = NULL;
char buff[100];
memset(buff,0,sizeof(buff));
printf(" Starting to open");
fd = fopen("test","r+");
if(NULL == fd)
{
printf("\n fopen() Error!!!\n");
return 1;
}
printf("\n File opened successfully through fopen()\n");
if(SIZE*NUMELEM != fread(buff,SIZE,NUMELEM,fd))
{
printf("\n fread() failed\n");
return 1;
}
最佳答案
因为你还没有读过 documentation fread()
。它返回 NUMELEM
,不 SIZE * NUMELEM
。
关于c - 为什么 fread() 在文件读取期间失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17586774/