/* hexdump.c */ /* Produce a dump in hexadecimal and ASCII of the standard input */ #include #include void dumpline( unsigned int loc, unsigned char values[], int count) { int num = 0; fprintf(stdout, "%8x - ", loc); while (num < count) { fprintf(stdout, "%02x ", values[num]); num = num + 1; } fprintf(stdout, "\n ", loc); num = 0; while (num < count) { if ((values[num] >= 32) && (values[num] < 127)) fprintf(stdout, "%02c ", values[num]); /* else if ((values[num] > 0) && (values[num] < 27)) fprintf(stdout, "\\%c ", values[num] + 0x60); */ else fprintf(stdout, " "); num = num + 1; } fprintf(stdout, "\n", loc); } int main() { unsigned int loc = 0; unsigned char bytes[16]; int howmany; howmany = fread(bytes, 1, 16, stdin); while (howmany > 0) { dumpline(loc, bytes, howmany); loc = loc + howmany; howmany = fread(bytes, 1, 16, stdin); } }