码迷,mamicode.com
首页 > 其他好文 > 详细

打印内存, 打印16进制

时间:2017-06-30 14:01:34      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:oid   int   argc   ret   strcpy   blog   16进制   printf   show   

 

打印内存信息

 1 #include <stdio.h>
 2
 3 // 打印内存信息
 4 void showMemoryHex(void* ptr, int size) {
 5     unsigned char* bytes = (unsigned char*)ptr;
 6     for (int i = 0; i < size; i++) {
 7         printf(" %02x", bytes[i]);
 8     }
 9 }

 

 测试

struct MyStruct {
    int age;
    char name[12];
};

int main(int argc, char* argv[])
{
    MyStruct tony;
    {
        memset(&tony, 0, sizeof(MyStruct));

        tony.age = 123;
        strcpy(tony.name, "tony");
    }


    MyStruct* pTony = &tony;
    showMemoryHex((void*)pTony, sizeof(MyStruct));
    getchar();
    return 0;
}

 

打印内存, 打印16进制

标签:oid   int   argc   ret   strcpy   blog   16进制   printf   show   

原文地址:http://www.cnblogs.com/baigoogledu/p/7098253.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!