Created
October 27, 2014 14:49
-
-
Save veapon/b3efb7b91739b112aef6 to your computer and use it in GitHub Desktop.
binread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILE *fin, *fout; | |
char *buf; | |
size_t len; | |
if (fopen_s(&fin, "1.jpg", "rb") != 0) { | |
printf("Error occured while opening 1.jpg.\n"); | |
return 0; | |
} | |
fseek(fin, 0, SEEK_END); | |
len = ftell(fin); | |
fseek(fin, 0, SEEK_SET); | |
printf("File size: %d\n", len); | |
if ((buf = (char *)malloc(len)) == NULL) { | |
printf("Error occured while malloc memory.\n"); | |
return 0; | |
} | |
fread(buf, sizeof(char), len, fin); | |
fclose(fin); | |
printf("buf: %s\n", buf); | |
// write | |
if (fopen_s(&fout, "1.out.jpg", "wb") != 0) { | |
printf("Error occured while opening 1.out.jpg.\n"); | |
return 0; | |
} | |
fputs(buf, fout); | |
fclose(fout); | |
free(buf); | |
while (1) {} | |
return 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment