/* John Pfeiffer 2010-06 display byte by byte values in console */
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
FILE* fp;
char c; /* sizeof(char) always equals 1 byte */
int i=0;
if( 2 != argc )
{ printf("wrong number of arguments, should be cat.exe filename\n");
exit(1);
}
fp = fopen(argv[1],"rb");
if( fp == NULL )
{ printf("error opening file\n");
}
else
{
c = getc(fp);
while( !feof(fp) )
{
i++;
printf("%x ", c ); /* cast a byte into unsigned int in hex */
if( i % 8 == 0){ printf("\n"); } /* readability */
c = getc(fp);
}
fclose(fp);
}
return( 0 );
}/* end main */