我正在寻找转换 C 中的现有代码以执行以下操作:我正在尝试编写一个十六进制转储程序来打印地址:值可打印字符。目前,值的代码以以下格式打印:
0003540: 05 04 06 75 6e 73 69 67 6e 65 64 20 63 68 61 72 ...unsigned char
所需的十六进制输出:
0003540: 0504 0675 6e73 6967 6e65 6420 6368 6172 ...unsigned char
当前代码成对打印:
addr = 0;
while ( ( cnt = ( long )
fread ( buf, sizeof ( unsigned char ), 16, filein ) ) > 0 ) {
b = buf;
/* Print the address in hexadecimal. */
fprintf ( fileout, "%07lx ", addr );
addr = addr + 16;
/* Print 16 data items, in pairs, in hexadecimal. */
cnt2 = 0;
for ( m = 0; m < 16; m++ ) {
cnt2 = cnt2 + 1;
if ( cnt2 <= cnt ) {
fprintf ( fileout, "%02x", *b++ );
}
else {
fprintf ( fileout, " " );
}
fprintf ( fileout, " " );
}
/* Print the printable characters, or a period if unprintable. */
fprintf ( fileout, " " );
cnt2 = 0;
for ( n = 0; n < 16; n++ ) {
cnt2 = cnt2 + 1;
if ( cnt2 <= cnt ) {
if ( ( buf[n] < 32 ) || ( buf[n] > 126 ) ) {
fprintf ( fileout, "%c", '.' );
}
else {
fprintf ( fileout, "%c", buf[n] );
}
}
}
fprintf( fileout, "\n" );
}
如何更改此代码以实现 AB12 CD34 格式?谢谢!