// code to hex dump files // Chris Lomont Sept 1995 // VC++ 2.0 #include #include #include #include int max_line; // set to 0 for all void hexdump(char * fname) { // dumps fname to screen FILE * infile; int count; unsigned char string[200],temp[10],text[50],ch; int line=0; infile = fopen(fname,"rb"); if (infile == NULL) { printf("Cannot open %s\n",fname); return; } while (!feof(infile)) { sprintf(string,"%05x: ",line); line+=16; for (count=0;count<16;count++) { if (count == 8) strcat(string," "); if (feof(infile)) break; ch = fgetc(infile); sprintf(temp,"%02x ",ch); strcat(string,temp); if (isprint(ch)) text[count] = ch; else text[count] = '.'; } text[count] = 0; printf("%s %s\n",string,text); } fclose(infile); } // hexdump void main(int argc, char * argv[]) { int count = 1; if (argc < 2) { printf("Usage: hexdump [options] file1 [file2 ...]\n"); printf("Dumps hex info for a file\n"); printf("No options currently supported\n"); // printf("Options: /mxxxx - max lines in hex\n"); exit(1); } // count = parse_options(argv); while (count < argc) hexdump(argv[count++]); } // main // hexdump.c