I try to read data from one PNG file, and want to write this data to the new file and save it.
I do such stuff like that:
FILE *fp = fopen("C:\\dev\\1.png", "rb");
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
rewind(fp);
char *buffer = (char*)malloc(sizeof(char)*size);
size_t result = fread(buffer, 1, size, fp);
FILE *tmpf = fopen("C:\\dev\\1_1.png", "wb");
fputs(buffer, tmpf);
fflush(tmpf);
fclose(tmpf);
I’ve got problem, that second file only has in its content, only that: ‰PNG SUB
In debugging , I have checked, long size = 652521, and size_t result has got the same size…
Don’t understand, why I can’t write all data to the second file…
Don’t use
fputs– usefwrite–fputsis for strings and will terminate on the first zero byte.Change:
to: