59 lines
877 B
C
59 lines
877 B
C
#include <stdio.h>
|
|
#include <memory.h>
|
|
#include <ctype.h>
|
|
|
|
int main( int argc, char *argv[] )
|
|
{
|
|
FILE *pFile = NULL;
|
|
long iAddr = 0;
|
|
char szBuf[16];
|
|
char szAsc[17];
|
|
int i, n;
|
|
|
|
if ( argc == 2 )
|
|
pFile = fopen( argv[1], "r" );
|
|
|
|
if ( !pFile )
|
|
{
|
|
perror( argv[1] );
|
|
return 1;
|
|
}
|
|
|
|
while( !feof(pFile) )
|
|
{
|
|
printf( "%08lx ", (long)iAddr );
|
|
|
|
n = fread( szBuf, 1, 16, pFile );
|
|
|
|
for( i=0 ; i<n ; i++ )
|
|
{
|
|
printf( "%02x ", szBuf[i] & 0xff );
|
|
}
|
|
|
|
for( i=n ; i<16 ; i++ )
|
|
{
|
|
printf( " " );
|
|
}
|
|
|
|
printf( " " );
|
|
|
|
memset( szAsc, ' ', 16 );
|
|
for( i=0 ; i<n ; i++ )
|
|
{
|
|
if ( isprint(szBuf[i]) )
|
|
szAsc[i] = szBuf[i];
|
|
else
|
|
szAsc[i] = '.';
|
|
}
|
|
szAsc[16] = '\0';
|
|
|
|
printf( "%s\n", szAsc );
|
|
|
|
iAddr += 16;
|
|
}
|
|
|
|
fclose( pFile );
|
|
return 0;
|
|
}
|
|
|