09月22日, 2014 1520次
晚上聊天
发现太多年没有写底层语言了 都不记得了
睡不着 扣定选手 随便扣点东西
#define _CRT_SECURE_NO_WARNINGS //vs2017 忽略安全 #include <stdio.h> #include <stdlib.h> #include <string.h> int isdebug = 0;//输出信息 int file2hex(char * filein, char *fileout) { FILE *pf = fopen(filein, "r"); if (pf == NULL) { printf("open %c file failed!\n", filein); exit(0); } FILE *pf2 = fopen(fileout, "w"); if (pf2 == NULL) { printf("open %c file failed!\n", fileout); fclose(pf); exit(0); } unsigned char ch; while (!feof(pf)) { ch = fgetc(pf); if (ch != NULL) { if (isdebug == 1) { printf("%c %d %02x\n", ch, ch, ch); } fprintf(pf2, "%02x", ch); } } fclose(pf2); fclose(pf); return 1; } int main(int argc, char *argv[]) { if (argc != 3 && argc!=4) { printf("Use : xxx.exe filein fileout \n"); printf("Use : xxx.exe filein fileout -detail \n"); exit(0); } if (argc == 4) { if (strcmp(argv[3], "-detail")==0) { isdebug = 1; } else { isdebug =0 ; } } char * filein = argv[1]; char *fileout = argv[2]; printf("输入文件: %s\n", filein); printf("输出文件: %s\n", fileout); int res=file2hex(filein, fileout); if (res == 1) { printf("处理完毕 ok = %d \n", res); } else { printf("处理失败 err = %d \n", res); } exit(0); }
暂无留言,赶快评论吧