Created
July 9, 2011 15:34
-
-
Save vext01/1073672 to your computer and use it in GitHub Desktop.
Dump a file to a C hex array
This file contains hidden or 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> | |
int | |
main(void) | |
{ | |
FILE *f, *out; | |
uint8_t buf; | |
unsigned long i = 0; | |
if ((f = fopen("silence.ogg", "r")) == NULL) | |
perror("failed to open"); | |
if ((out = fopen("array.c", "w")) == NULL) | |
perror("failed to open"); | |
fprintf(out, "unit8_t silence[] = { "); | |
while (fread(&buf, 1, 1, f)) { | |
if (i++ % 10 == 0) { | |
if (fseek(out, ftell(out)-1, SEEK_SET) != 0) | |
perror("seek"); | |
fprintf(out, "\n\t"); | |
} | |
fprintf(out, "0x%02x, ", buf); | |
} | |
if (fseek(out, ftell(out)-2, SEEK_SET) != 0) | |
perror("seek"); | |
fprintf(out, "\n};"); | |
fclose(f); | |
fclose(out); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment