#include <stdio.h>
#include <string.h>
#include <ctype.h>
static const char * const hex_digit = "0123456789ABCDEF";
static char quickhex (int i)
{
return hex_digit[i];
}
static void memdump (void *pv, size_t num)
{
int i;
unsigned char *pc = (unsigned char *) pv;
for (i = 0; i < num; i++)
printf ("%c%c ", quickhex (pc[i] >> 4), quickhex (pc[i] & 0x0f));
printf ("\t");
for (i = 0; i < num; i++)
printf ("%c", isprint (pc[i]) ? pc[i] : '.');
printf ("\n");
}
int main()
{
char *str = "A~";
memdump( str, strlen(str) );
return 0;
}
memdump的C语言实现
最新推荐文章于 2024-03-30 01:19:28 发布
这段代码展示了如何使用C语言实现内存块的十六进制转储。它定义了一个函数`quickhex`用于将十进制数字转换为十六进制字符,并定义了`memdump`函数来打印内存区域的内容,以十六进制和可打印字符形式展示。
摘要由CSDN通过智能技术生成