C: How to read a jpg from a file and save it? -


i having trouble reading jpg file , saving it. want implement file sharing system between client , server , unable read jpg , save on same process. here have far

int main(int argc, const char * argv[]) {     char *buffer;     file *picture;     file *newpicture;     struct stat st;     long filesize = 0;       picture = fopen("path/root/game-of-thrones-poster.jpg", "rb");     fstat(picture, &st);     filesize = st.st_size;     if(filesize > 0) {         buffer = malloc(filesize);          if(read(picture, buffer, filesize) < 0) {             printf("error reading file");         }         fclose(picture);          newpicture = fopen("path/root/new.jpg", "wb");         write(newpicture, buffer, filesize);     }     free(buffer); } 

when tries read file, tells me filesize 0.

fstat() identical stat(), except file stat-ed specified file descriptor fd.

you passing file *, fstat expects int


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -