#include “iostream”
#include “stdio.h”
#include “fstream”
using namespace std;
int main()
{
char szInFileName[80];
char szOutFileName[80];
int zz=0;
cout<<“Please type the file name for chang:”<<endl;
cin>>szInFileName;
cout<<“Please input the file name for output:”<<endl;
cin>>szOutFileName;
FILE *ifp;
if((ifp=fopen(szInFileName,“r”)) == NULL)
{
cout<<“Open file to read failed”<<endl;
goto ERRO;
}
FILE *ofp;
if((ofp=fopen(szOutFileName,“w”)) == NULL)
{
cout<<“Open file to write failed”<<endl;
goto ERRO;
}
int iBuf,iColCount,iRowCount;
iColCount=iRowCount=0;
while(feof(ifp) == 0)
{
iBuf=fgetc(ifp);
if(iBuf<=15)
{
zz++;
fprintf(ofp,"‘0x0%x’,",iBuf);
if(zz%10 == 0)fprintf(ofp,"\n",iBuf);
}
else
{
zz++;
fprintf(ofp,"‘0x%x’,",iBuf);
if(zz%10 == 0)fprintf(ofp,"\n",iBuf);
}
//if(++iColCount == 64)
//{
//iColCount=0;
//fprintf(ofp,"/n");
//if(++iRowCount==8)
//{
//iRowCount=0;
//fprintf(ofp,"/n");
//}
//}
}
printf(“zz %d\n”,zz);
ERRO:
fclose(ifp);
fclose(ofp);
return 0;
}
文件转16进制
最新推荐文章于 2024-05-11 22:42:50 发布