该工具在C中的开发人员命令提示符中进行编译。它将向终端显示输出,并在创建的“ array_name.c”文件中显示内容。请注意,某些终端可能会显示“ \ b”字符。
#include <stdio.h>
#include <assert.h>
int main(int argc, char** argv) {
assert(argc == 2);
char* fn = argv[1];
FILE* f = fopen(fn, "rb");
FILE* fw = fopen("array_name.c","w");
printf("char array_name[] = {\n");
fprintf(fw,"char hex_array[] = {\n");
unsigned long n = 0;
while((!feof(f))){
unsigned char c;
if(fread(&c, 1, 1, f) == 0) break;
printf("0x%.2X,", (int)c);
fprintf(fw,"0x%.2X,", (int)c);
++n;
if(n % 20 == 0){
printf("\n");
fprintf(fw,"\n");
}
}
fseek(fw, -1, SEEK_CUR);
printf("\b};\n");
fprintf(fw,"};\n");
fclose(f);
fclose(fw);
}