每日一算法:二进制文件的处理
【摘要】 // 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[] =...
-
// BinToHex.cpp : Defines the entry point for the console application.
-
//
-
-
#include "stdafx.h"
-
#include "BinToHex.h"
-
-
#ifdef _DEBUG
-
#define new DEBUG_NEW
-
#undef THIS_FILE
-
static char THIS_FILE[] = __FILE__;
-
#endif
-
-
/
-
// The one and only application object
-
-
CWinApp 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;
-
}
文章来源: blog.csdn.net,作者:悦来客栈的老板,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq523176585/article/details/14517141
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)