- #include<stdio.h>
- #include<ctype.h>
- #include<stdlib.h>
- #include<string.h>
- void dump_memory(int type, void *address, int n){
- int i;
- int k=0;
- int length;
- int longest=0;
- switch(type){
- case 1:
- for(i=0;i<n;i++){
- if(i != (n-1)){
- if(i%6==0){
- printf("%08X:",(unsigned int)address+i);
- printf(" %08X",*((int*)address+i));
- }
- if(i%6==5)
- printf(" %08X\n",*((int*)address+i));
- if(((i%6)!=0)&&((i%6)!=5))
- printf(" %08X",*((int*)address+i));
- }
- if(i==(n-1)){
- if(i%6==0){
- printf("%08X:",(unsigned int)address+i);
- printf(" %08X\n",*((int*)address+i));
- }
- if((i%6)!=0)
- printf(" %08X\n",*((int*)address+i));
- }
- }
- break;
- case 2:
- for(i=0;i<n;i++){
- if(i != (n-1)){
- if(isprint(*((char*)address+i))!=0){
- if(i%8==0){
- printf("%08X: ",(unsigned int)address+i);
- printf("%-4c ",*((char*)address+i));
- }
- if(i%8==7)
- printf("%-4c\n",*((char*)address+i));
- if((i%8!=0)&&(i%8!=7))
- printf("%-4c ",*((char*)address+i));
- }
- else{
- if(i%8==0){
- printf("%08X: ",(unsigned int)address+i);
- printf("0x%2x ",*((unsigned char*)address+i));
- }
- if(i%8==7)
- printf("0x%2x\n",*((unsigned char*)address+i));
- if((i%8!=0)&&(i%8!=7))
- printf("0x%2x ",*((unsigned char*)address+i));
- }
- }
- if(i == (n-1)){
- if(isprint(*((char*)address+i))!=0){
- if(i%8==0){
- printf("%08X: ",(unsigned int)address+i);
- printf("%-4c\n",*((char*)address+i));
- }
- if(i%8==7)
- printf("%-4c\n",*((char*)address+i));
- if((i%8!=0)&&(i%8!=7))
- printf("%-4c\n",*((char*)address+i));
- }
- else{
- if(i%8==0){
- printf("%08X: ",(unsigned int)address+i);
- printf("0x%2x\n",*((unsigned char*)address+i));
- }
- if(i%8==7)
- printf("0x%2x\n",*((unsigned char*)address+i));
- if((i%8!=0)&&(i%8!=7))
- printf("0x%2x\n",*((unsigned char*)address+i));
- }
- }
- }
- break;
- case 3:
- for(i=0;i<n;i++){
- if(i%4==0){
- printf("%08X: ",(unsigned int)address+i);
- printf("%15e ",*((double*)address+i));
- }
- if(i%4==3)
- printf("%15e\n",*((double*)address+i));
- if((i%4!=0)&&(i%4!=3))
- printf("%15e ",*((double*)address+i));
- }
- break;
- case 4:
- for(i=0;i<n;i++){
- length=strlen( (char*)address+i );
- if(length>longest)
- longest=length;
- }
- for(i=0;i<n;i++){
- printf("%08X: ",(unsigned int)address+k);
- printf("%*c\n",longest,*((char*)address+k));
- k=1+strlen((char*)address+k);
- }
- break;
- }
- }
- int main(){
- int a[200]={22,3,5,5,5,6,7,8};
- dump_memory(1,a,8);
- system("pause");
- return 0;
- }
Raw Paste