Chinaunix首页 | 论坛 | 博客
  • 博客访问: 408065
  • 博文数量: 121
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1393
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-11 12:17
个人简介

www.vibexie.com vibexie@qq.com

文章分类

全部博文(121)

文章存档

2015年(55)

2014年(66)

我的朋友

分类: C/C++

2014-03-25 00:31:07


点击(此处)折叠或打开

  1. #include<stdio.h>
  2. #include<ctype.h>

  3. typedef unsigned char BYTE;

  4. int main()
  5. {
  6.     unsigned int addr;
  7.     int i,n;
  8.     BYTE *ptr;

  9.     printf("Address of main function: 0x%08x\n",(unsigned int)main);
  10.     printf("Address of addr variable: 0x%08x\n",(unsigned int)&addr);
  11.     printf("\nEnter a (hex)address:0x");
  12.     scanf("%x",&addr);
  13.     printf("Enter number of bytes to view:");
  14.     scanf("%d",&n);

  15.     printf("\n");
  16.     printf("Address Bytes Characters\n");
  17.     printf("---------- ------------------------------- ----------");
  18.     printf("\n");
  19.     ptr=(BYTE*)addr;
  20.     for(;n>0;n-=10)
  21.     {
  22.         printf("0x%08x ",(unsigned int)ptr);
  23.         for(i=0;i<10 && i<n;i++)
  24.             printf("%.2x ",*(ptr+i));
  25.         for(;i<10;i++)
  26.             printf(" ");
  27.         printf(" ");
  28.         for(i=0;i<10 && i<n;i++)
  29.         {
  30.             BYTE ch=*(ptr+i);
  31.             if(!isprint(ch))
  32.                 ch='.';
  33.             printf("%c",ch);
  34.         }

  35.         printf("\n");
  36.         ptr+=10;
  37.     }


  38.     return 0;
  39. }

阅读(1603) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~