一个memdump函数

#include 
//#include "getopt.h"

#include 
#include 
#include 
#include 
#include 

#ifdef _WIN32
#include 
#include 
#include 
#else
#include
#endif
#include 
using namespace std;



//http://blog.csdn.net/zhengdy/article/details/5451134
void MemDmp(const void *adr, int len) {
    const char *hex_ch = "0123456789ABCDEF";
    const char *fmt    = "[%08X]  %.8s %.8s %.8s %.8s  * %.16s *\n";
    const char *base_adr, *curr_adr;
    unsigned char  hex[16<<4], asc[16];

    base_adr = curr_adr = (const char *)adr;
    for (unsigned int ix=0, num=len/16, rem=len%16; ix <= num; ix++){
        unsigned int iy;
        memset(hex,' ',16<<1);
        memset(asc,' ',sizeof(asc));
        for (iy=0; iy < ((ix>4)];
            hex[(iy<<1)+1] = hex_ch[0x0F&(base_adr[(ix<<4)+iy])   ];
            asc[iy]=((unsigned char)base_adr[(ix<<4)+iy]<=' ') ? '.' : base_adr[(ix<<4)+iy];
        }
        if ((ix0)){
            hex[iy<<1]=' ';
            printf(fmt,curr_adr,hex+0,hex+8,hex+16,hex+24,asc); fflush(stdout);
            curr_adr += 16;
        }
    }
}

typedef struct Student{      //声明一个结构体类型Student
    int num;         //声明一个整形变量num
    char name[20];   //声明一个字符型数组name
    char sex;        //声明一个字符型变量sex
    int age;         //声明一个整形变量age
} Student;


int main()
{
    struct tm  *ar;
    time_t tx;
    tx = (time_t)time(NULL);
    ar = localtime(&tx);
    MemDmp(ar, sizeof(struct tm));

    Student student1,student2;// 定义结构体类型变量student1和student2
    //cout<

你可能感兴趣的:(c/c++)