c - read an empty file with fread -


i trying read empty file fread. before created file blocksize of 4096 , amount of 40 blocks. @ moment know these blocks "empty" if read file in code below cannot tell wether empty or not. mean expecting nread null or that. know have compare nread with? thank you!

int test() {     char buf[4096];    file *file;    size_t nread;     file = fopen("out/abc.store", "r");    if (file) {        while ((nread = fread(buf, 1, sizeof buf, file)) > 0)           fwrite(buf, 1, nread, stdout);       if (ferror(file)) {       /*error handling*/    }    fclose(file); } 

edit:

i created file that:

char *content=(char*)malloc(uintblocksize*uintblockcount); memset(content,0,uintblocksize*uintblockcount); ...  while (i!=0)  {    check=fwrite(content,uintblocksize, 1, storefile);    if (check!=1)        return 1;    i--;  } 

check see if fread returned 0. documentation (here):

the total number of elements read returned.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -