Chinaunix首页 | 论坛 | 博客
  • 博客访问: 368512
  • 博文数量: 715
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5005
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:46
文章分类

全部博文(715)

文章存档

2011年(1)

2008年(714)

我的朋友

分类:

2008-10-13 16:32:09

#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["231, fp);
        memset(cnum, 
011);
        itoa(fEnd
-fSet, cnum, 10);
        fwrite(cnum, 
sizeof(cnum), 1, fp);
        fwrite(
"] = { "61, fp);        
        num 
= (fEnd-fSet)/16;
        last 
= (fEnd-fSet)%16;
        
for(i = 0; i < num; i++)
        
{
            
for(j = 0; j < 16; j++)
            
{
                memset(ch, 
06);
                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(
" "11, 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(
"}"11, fp);
        free(pb);
        fclose(v_fpLog);
        fclose(fp);
    }

    
return 0;
}

--------------------next---------------------

阅读(132) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~