hex2c.cpp

来自「将HEX文件转换成TXT文本的程序.该程序可以把DSP的待烧写程序转换为文本文件」· C++ 代码 · 共 102 行

CPP
102
字号
//////////////////////////////////////////////////////////////////////
//
// File: hex2c.c
// $Archive: /USB/Util/hex2c/hex2c.c $
//
// Purpose:
// Utility to convert Intel Hex flies into C source code
//
// Environment:
//
// $Author: o4icwin $
//

//////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>



void main()
{
char *str=(char *)malloc(1000); 
///char  ch;


FILE *fp=fopen("ex6.hex","r");
FILE *fp2=fopen("ex6.dat","w");//NULL ;
int i=0;
int j=1;
  

fgets(str,2,fp);
cout<<str<<endl;

//cout<<"iio";//str;//<<endl;

fgets(str,2,fp);
cout<<str<<endl;



while (!feof(fp))
{ 
   fgets(str,2,fp);
   if (*str==10)
   { 
	   j--;
   }
  // ch=*str;
   if(j%6==1)
    {fputs("0x",fp2);
     fputs(str,fp2);
    }
   if(j%6==2)
    {
     fputs(str,fp2);
    }
   if(j%6==3)
    {
    // fputs(str,fp2);
    }
   if(j%6==4)
    {
     fputs(str,fp2);
    }
    if(j%6==5)
    {
     fputs(str,fp2);
    }
    if(j%6==0)
    {
     fputs(",",fp2);
     if (i>11)

       {fputs("\n",fp2);//change line
	    //fputs("",fp2);//change line
       i=0;//recounter
	   
       }
     i++;
    }
   j++;
  } 
  fclose(fp);
   fclose(fp2);
getch();

}
  
    








⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?