creates unsigned char array from bin data
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> | |
int main(int argc, char **argv) | |
{ | |
FILE *fp; | |
int cur, c, prevc; | |
if(argc < 2) { | |
fprintf(stderr, "You should provide a filename.\n"); | |
return 1; | |
} | |
if(!(fp = fopen(argv[1], "rb"))) { | |
fprintf(stderr, "Failed to open file %s\n", argv[1]); | |
return 1; | |
} | |
printf("unsigned char data[] = {\n\t"); | |
cur = 8; | |
if((prevc = fgetc(fp)) == -1) { | |
fprintf(stderr, "File %s is empty\n", argv[1]); | |
return 1; | |
} | |
while((c = fgetc(fp)) != -1) { | |
cur += printf("%u,", (unsigned int)prevc); | |
if(cur >= 72) { | |
printf("\n\t"); | |
cur = 8; | |
} else { | |
putchar(' '); | |
cur++; | |
} | |
prevc = c; | |
} | |
printf("%u\n};\n", prevc); | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment