每日一算法:二进制文件的处理

来源:互联网 发布:手机淘宝怎么登录注册 编辑:程序博客网 时间:2024/05/02 00:05
// BinToHex.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "BinToHex.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// The one and only application objectCWinApp theApp;using namespace std;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]){CString FileNameSrc = argv[1];CString FileNameTag = FileNameSrc + ".h";FILE *fp1;FILE *fp2;int ch;int count = 0;fp1 = fopen(FileNameSrc,"rb");if (!fp1){return 0;}fp2 = fopen(FileNameTag,"wb+");fputs("const unsigned char BintoHex[]={ \r\n\r\n",fp2);while (((ch = fgetc(fp1))) != EOF){//每读取一个字符,在它前面添加0x,后面添加 , 号,fputs("0x",fp2);if (ch <= 0xf){fputc('0',fp2);}fprintf(fp2,"%X",ch);fputc(',',fp2);count++;if (count % 16 == 0){fputs("\r\n",fp2);}}fputs("\r\n}",fp2);fclose(fp1);fclose(fp2);return 0;}

原创粉丝点击