-
-
Save symisc/9b6fb1c1633637db4409c7e2b3bd05d0 to your computer and use it in GitHub Desktop.
bin2c
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
#include <stdio.h> | |
#include <assert.h> | |
int main(int argc, char** argv) { | |
assert(argc == 2); | |
char* fn = argv[1]; | |
FILE* f = fopen(fn, "r"); | |
printf("char a[] = {\n"); | |
unsigned long n = 0; | |
while(!feof(f)) { | |
unsigned char c; | |
if(fread(&c, 1, 1, f) == 0) break; | |
printf("0x%.2X,", (int)c); | |
++n; | |
if(n % 10 == 0) printf("\n"); | |
} | |
fclose(f); | |
printf("};\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment