View Single Post
  #6 (permalink)  
Old March 30th, 2004, 01:59 PM
davekw7x davekw7x is offline
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I am starting to see the light (I think). I thought the file was
binary bytes, not ASCII representations.

So, use getline to read the entire file into your buffer. (How large
must the buffer be? Something like 789-794 bytes, I think, since
each file entry takes three bytes (two for the two ASCII chars)
plus a space to separate successive file entries.)

So each entry occupies three bytes (the two ASCII characters plus a
space). The last byte may or may not have a space. There may or may
not be a carriage return after the last byte.

What is the index of the two characters in the buffer that tell you
the length of the body? In your example, the length is 39(hex) (the
fifth byte).
I think the two characters in filedata[12] and filedata[13] must
be converted to an int so that you will know the length. (For debug
purposes, do cout << filedata[12] << filedata[13].)

Nothing really fancy is needed, but you have to do a little work:
What you need is the integer value corresponding to the character
in filedata[12] and the integer value corresponding to the character
in filedata[13].

For example: int1 = filedata[12] - '0';
             int2 = filedata[13] - '0';

Since these are the digits of a hexadecimal number, the number of
bytes in the body is equal to 16*int1 + int2.

Now you still have to format the output appropriately:

Each byte is two chars plus a space
endl after the first five bytes
endl after the sixth byte
Then, for the body of the file, endl after each 16 bytes.

etc.

Dave
Reply With Quote