user418304 user418304 - 1 year ago 192
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");
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);

Answer Source

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

 fread(aByte,1, sizeof(aByte),  file);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download