Tips for Project 1… (Thanks to Ed Frey!)

 

 

  1. declare your single char variable as an unsigned short.  For example:

unsigned short inBuffer;

  1. declare your input buffer as an array of unsigned char.  For example:

unsigned char buffer[100];


3.   use fscanf instead of scanf since you will be reading from a file

4. use either the format string “%2hx” or “%02x”  Both of these is valid on many systems, but the “%02x”  string may not work in your particular implementation.  If you have trouble,  use “%2hx”.


  1. The read in and print out statement may look something like:



fscanf(fin,"%2hx", &inBuffer);

printf("'%02hx'\n",inBuffer);

buffer[i] = (char)inBuffer;