#include "stdio.h"
#include "stdlib.h"
#include "memory.h"
int main()
{
FILE *v_fpLog, *fp;
int fSet = 0, fEnd = 0, i, j;
int filelen = 0, num, last, r;
char *pb, ch[6], cnum[11];
if ( (v_fpLog = fopen( "sjf.bin" , "rb+")) == NULL || (fp = fopen( "out.txt" , "w+a+")) == NULL)
{
printf( "The file was not opened");
return 0;
}
else
{
fseek( v_fpLog, 0, SEEK_SET );
fSet = ftell( v_fpLog );
fseek( v_fpLog, 0, SEEK_END );
fEnd = ftell( v_fpLog );
pb = (char *)malloc(fEnd - fSet );
fseek( v_fpLog, 0, SEEK_SET );
fread(pb, fEnd - fSet, 1, v_fpLog);
fwrite("unsigned char boot_bin[", 23, 1, fp);
memset(cnum, 0, 11);
itoa(fEnd-fSet, cnum, 10);
fwrite(cnum, sizeof(cnum), 1, fp);
fwrite("] = { ", 6, 1, fp);
num = (fEnd-fSet)/16;
last = (fEnd-fSet)%16;
for(i = 0; i < num; i++)
{
for(j = 0; j < 16; j++)
{
memset(ch, 0, 6);
r = (int)pb[j + 16 * i];
r = r & (0xFF);
sprintf(ch, "0x%02x,", r);
r = fwrite(ch, sizeof(ch), 1, fp);
printf("%s ", ch);
}
fwrite(" ", 1, 1, fp);
printf(" ");
}
for(i = 0; i < last; i++)
{
r = (int)pb[i + 16 * num];
r = r & (0xFF);
sprintf(ch, "0x%02x,", r);
fwrite(ch, sizeof(ch), 1, fp);
printf("%s ", ch);
}
fwrite("}", 1, 1, fp);
free(pb);
fclose(v_fpLog);
fclose(fp);
}
return 0;
}--------------------next---------------------
阅读(132) | 评论(0) | 转发(0) |