user418304 user418304 - 2 months ago 21
C Question

Why does fread always return 0?

I used this code to read file. But fread function always return 0. What is my mistake?

FILE *file = fopen(pathToSourceFile, "rb");
if(file!=NULL)
{
char aByte[50000];
int ret = fread(aByte, sizeof(aByte), 1, file);
if(ret != 0)
{
not jump into there;
fseek(file, 0, SEEK_SET);
fwrite(aByte, ret, 1, file);
}
}
fclose(file);

Answer

are you sure that your file has a size greater than 50000 ? else you could try:

 fread(aByte,1, sizeof(aByte),  file);
Comments