- #include<stdio.h>
- #include<string.h>
- #include <ctype.h>
- void dump_memory(int type, void *address, int n) ;
- int main()
- {
- int i , j ;
- /*char *a , *k ;
- k = a ;
- for( i = 0 ; i<4 ; i++ )
- {
- scanf( "%s" , a ) ;
- *( a + strlen(a) ) = '\0' ;
- a += strlen(a)+1 ;
- }
- dump_memory( 4 , k , 4 ) ;*/
- //char a[15] = { "1\nwe2f\054f5\0fwrg" };
- double a[9] ;
- for( i = 0 ; i<9 ; i++ )
- scanf( "%lf" , &a[i] ) ;
- dump_memory( 2 , a , 9 ) ;
- scanf( " " ) ;
- }
- void dump_memory(int type, void *address, int n)
- {
- int i , j ;
- if( type == 1 )
- {
- for( i = 0 ; i<n ; i++ )
- {
- if( i%6 == 0 )
- printf( "%08X:" , (unsigned int*)address + i ) ;
- printf( " %08X" , *( (unsigned int*)address+i ) ) ;
- if( i%6 == 5 )
- putchar( '\n' ) ;
- }
- }
- else if( type == 2 )
- {
- for( i = 0 ; i<n ; i++ )
- {
- if( i%4 == 0 )
- printf( "%08X:" , (double*)address + i ) ;
- printf( " %15e" , *( (double*)address+i ) ) ;
- if( i%4 == 3 )
- putchar( '\n' ) ;
- }
- }
- else if( type == 3 )
- {
- for( i = 0 ; i<n ; i++ )
- {
- if( i%8 == 0 )
- printf( "%08X:" , (char*)address + i ) ;
- if( isprint( *( (char*)address+i ) ) )
- printf( " %-4c" , *( (char*)address+i ) ) ;
- else
- printf( " 0x%02X" , *( (char*)address+i) ) ;
- if( i%8 == 7 )
- putchar( '\n' ) ;
- }
- }
- else
- {
- int longest = 0 ;
- for( i = 0 , j = 0 ; i<n ; i++ )
- {
- if( strlen( (char*)address+j ) > longest )
- longest = strlen( (char*)address+j ) ;
- j += ( strlen( (char*)address+j )+1 ) ;
- }
- for( i = 0 , j = 0 ; i<n ; i++ )
- {
- printf("%08X: %*s\n", ( char* )address + j , longest , ( char* )address + j );
- j += (strlen( (char*)address+j )+1) ;
- }
- }
- }
Raw Paste