/*
This program converts an object file into a hexdecimal file.
by Jeff Chai - Public Domain
NOTE: know to compile under TC 3.0, DJGPP, and MS Developer Studio.
*/
// Include header files
#include
#include
#include
// Main program starts here
int main( int argc, char **argv )
{
FILE *obj_in; // Declare a file pointer
unsigned char byte_in; // A byte buffer
static char hex[] = {"0123456789ABCDEF"}; // ASCII code
int hi, lo, i; // high, low nibbles and index
// Open the object file using name in argv[]
if( (obj_in = fopen(argv[1],"rb" )) == NULL )
{
// NULL returned, file does not exist.
fprintf( stderr, "Couldn't open %s\n",argv[1] );
return 1;
}
i = 1;
while( !feof(obj_in) ) // While Not End-of-file, loop
{
// Get one unsigned character from file
byte_in = fgetc( obj_in);
if (!feof(obj_in)) // not an EOF character
{
// Shift right 4 bits to get the high nibble
hi = byte_in /16;
// Mask off high nibble to get the low nibble
lo = byte_in & 0xF;
// Put the corresponding Hexdec charecter out
fputc( hex[hi], stdout );
// Put the corresponding Hexdec charecter out
fputc( hex[lo], stdout );
if (i > 5) // Put a new line character every 6 bytes
{
i = 0;
fputc ('\n',stdout);
}
++i;
} // End if
} // End of loop
// DONE, close file
fclose(obj_in);
return 0; // Return 0 to indicate a normal return
} // End of program
               (
geocities.com/tutorman_2000)