Sometimes if you need to download a bin file to flash to go, but do not know which way to go download. At this time we can bin file into a const array, and then in the code called directly on it. But how transformation Nigeria needs? UE tool can be transformed but little trouble, then write a simple conversion function of it, with the windows compiler tool chain can be achieved (there are specific installation methods run in my previous blog), ado, on the code
#include <stdio.h>
int main()
{
FILE *fb = NULL;
FILE *fh = NULL;
int i = 322;//文件大小,需要根据实际的文件大小修改
int j = 0;
int value=0;
fb = fopen("example.bin","rb"); //需要转化的bin文件
fh = fopen("example.txt","a+"); //需要合成的hex文件
while(i)
{
value = fgetc(fb);
fprintf(fh, "0x%02x,",value);//格式化输出到文件中去
i--;
j++;
if(j >=20) //每20个字节换行一次
{
fputc('\n',fh);
j=0;
}
}
fclose(fb);
fclose(fh);
return 0;
}