Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does fread always return 0?

Tags:

c

file-io

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); 
like image 736
websitesvalues Avatar asked Aug 29 '10 11:08

websitesvalues


1 Answers

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

 fread(aByte,1, sizeof(aByte),  file);
like image 100
Pierre Avatar answered Oct 17 '22 05:10

Pierre