Skip to content

Instantly share code, notes, and snippets.

@OlivierLDff
Forked from albertz/bin2c.c
Last active October 29, 2018 16:23
Show Gist options
  • Save OlivierLDff/fea07ef2c20acab45472a1b1a0680a98 to your computer and use it in GitHub Desktop.
Save OlivierLDff/fea07ef2c20acab45472a1b1a0680a98 to your computer and use it in GitHub Desktop.
bin2c
// https://gist.github.com/albertz/1551304
#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