Thread: Hopefully simple question, input streams

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250

    Hopefully simple question, input streams

    Hopefully this is a simple question. I searched out for it, but found nothing. Basically I just need to know some simple info.

    Basically I am reading in a file in binary using ifstream. All is fine and good, then I hit some spaces, and then it gets all wacky from there.

    I setup a char array of 4 bytes and read in 4 bytes at a time. This works for a while until I hit a part of the file and then it starts to read spaces and messes up what I am reading.

    So for example:

    ...

    Code:
    char *tempPtr;
    char tempVal[4];
    
    in.read( tempVal, 4 );  //say for instance a line in hex 34F2
    //format the string into hex
    long value = strtol(  tempVal, &tempPtr, 16 );
    then it hits a line with a space, ( I can see the raw file as well, and in a hex editor it ignores these, so I can assume there is a way to decide what is a is not a space / \n), and then gets a little funky...

    same code as before, on a particular 8 bytes...

    Code:
    char *tempPtr;
    char tempVal[4];
    
    in.read( tempVal, 4 );  //line is 0000 0106 0DEE 05AB
    //format the string into hex
    CString temp;
    temp.Format( "%02X%02X%02X%02X", tempVal[0], tempVal[1], tempVal[2], tempVal[3] );  
    
    in.read( tempVal, 4 );  // read in the second part of the above line
    //format the string into hex
    CString temp1;
    temp1.Format( "%02X%02X%02X%02X", tempVal[0], tempVal[1], tempVal[2], tempVal[3] );  
    
    CString joined = temp + temp1;

    This should come out as normal, but when I hit the spaces it comes out more like this...

    0000 0106 0DFFFFEEFFFF05AB

    which to me seems impossible, but hey, I am no expert either .

    Any simple mistakes anyone sees with that? I am hesitant to eradicate all FF's ( space in ascii ) because there are of course numbers which have FF in them. Any ideas on this? I am kinda not able to spot it, but perhaps someone has a good way to id them. Thanks!
    Last edited by dpro; 03-08-2006 at 10:41 PM. Reason: Well it would help to get the code correct it would seem!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  3. Very very simple file input question.
    By Kurisu33 in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2006, 11:37 PM
  4. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 11:28 PM