/* ファイルの中身を16進数で表示する */ #include #include main() { char fname[40]; FILE *fp; int col; int c; static char str[17]; printf("Input Filename: "); scanf("%s", fname ); if( !(fp = fopen( fname, "rb")) ) { printf("\"%s\" not found!", fname ); exit(1); } col = 0; while( feof(fp) == 0 ) { if( col == 0 ) printf("%04x: ", ftell(fp) ); c = getc(fp) & 0xFF; printf("%02x ", c ); str[col] = isprint(c) ? c : '.'; col++; if( col > 15 ) { printf(" %s\n", str ); col = 0; } } if( col > 0 ) { str[col] = '\0'; while( col++ < 16 ) printf(" "); printf(" %s\n", str ); } fclose(fp); } /* end of hd3.c */