( Index )

Brief Information about the Sept '03 CSIG Meeting

Two Hex Dump Programs and a Comparison of

C Basic I/O vs. C++ Stream Class I/O

B. Arnold

Hex Dump

Welcome back to a new season of the CSIG, a Special Interest Group of the ACGNJ. The subject for this month is an introduction to C and C++ programming and an interesting comparison between two of the popular libraries used with the language. Although the two programs presented were compiled using the Microsoft Visual C++ version 6.0 compiler, since they are text based programs they will work with many other compilers.

Input and Output coding in C and C++ has evolved into two major libraries. For example, since the beginning of K&R programs, the STDIO.H library with its PRINTF statements has been used by thousands of programmers. More recently, as part of the C++ standard library, the IOStream library has presented a different philosophy of doing I/O. Today, either method may be used but the programmer normally chooses one or the other for any particular program.

The two programs are "sister" programs which allow the viewing of information within otherwise unreadable files such as executables, zip files, bitmap files, etc. As shown in the example, they produce a hexadecimal dump of the target file. Each program is about a page in length. One is written in C and the other in C++. (As usual, these programs and the source code may be downloaded from the ACGNJ ftp site.)

Sample Code

void main(int argc, char *argv[])
    FILE *fs1;
    long offset=0L;     int n;    unsigned char buff[20];
    if (argc < 2)
        fprintf(stderr,VERSION);  return;
    fs1 = fopen(argv[1],"rb");
    if (fs1 == NULL)
        perror(argv[1]); fprintf(stderr,VERSION); return;
    printf("\t\t HEX DUMP OF FILE ----->>> %s\n\n",argv[1]);
    while((n = fread(buff,1,16,fs1)) > 0)
        printf("%07X   ",offset); 
        hex_printf(buff, n);
        offset += 16;

void hex_printf(unsigned char arg[],int count)  // HEX PRINT A LINE
    {                                           // ----------------------
    int i;

    for(i=0; i<count; i++) printf("%02X ", arg[i]);  // Hex bytes first
    for(   ; i<16   ; i++) printf("   ");
    printf("   ");
    for(i=0; i<count; i++) putchar(clean( arg[i]));  // Now ascii info
    for(   ; i<16   ; i++) putchar(' ');

"Random Access" questions start at 7:30 Tuesday night.


Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page