hex2txt.c

来自「converting tool from hex file to text fi」· C语言 代码 · 共 50 行

C
50
字号
#include "stdio.h"
#include "math.h"

int
main( int ac, char **av )
{
	
	FILE *file1, *file2;
	int n1;
	unsigned char n2;
	int end;

	if(ac < 3)
	{
		printf("Command Format: hex2txt srcFile dstFile\n");
		return 1;
	}

	file1 = fopen(av[1],"rb");
	file2 = fopen(av[2],"w");
	if((file1 == NULL)||(file2 == NULL))
	{
		printf("Cannot open files\n");
		return 1;
	}
	end = 0;
	while(1)
	{
	    for(n1 = 0;n1 <16;n1++)
	    {
		    if(fscanf(file1,"%c",&n2) == EOF)
		    {
		        end = 1;
		        break;
		    }
		    else
		    {
    		    fprintf(file2, "0x%02x, ", n2);
		    }
		}
		if(end == 1) break;
		fprintf(file2, "\n");
	}
	
	fclose(file1);
	fclose(file2);

	return 0;

}

⌨️ 快捷键说明

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