Thread: Zero Values being ignored for output (hexadecimal)

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252

    Zero Values being ignored for output (hexadecimal)

    As you can tell by my chosen member name, I'm aging and with little patience (and time).
    My problem is probably simple, but alludes me.

    Code:
    unsigned char data_new[8]="\xBE\xBA\xCE\x0A\x00\x00\x00\x00";
    My trouble is, I'm getting the hexadecimal output I was going for, but the zero values are
    being ignored (output stops at BEBA CE0A) and those zero bytes are needed for header
    intregrity.

    Any help would be appreciated (it's almost past my bedtime. lol).

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    How are you attempting to output this data?
    You're not using string functions, are you?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Most likely, the wrong way;

    Code:
    fstream fout("header.raw", ios::out | ios::binary | ios::end );
       fout <<data_new<<std::endl;
    
    fout.close();
    As I said, I'm getting part of the data I want, but the following 0000 0000 and et cetera aren't being written.

    I was trying to do this short n' sweet by using the escape sequence for recognition of hex data.
    Last edited by Oldman47; 12-11-2006 at 08:55 PM.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    If it's binary, shouldn't you be using .write() and specifying the object size?

    [edit]That is, something like this?
    Code:
    #include <fstream>
    
    int main(void)
    {
       unsigned char data_new[8]= {0xBE,0xBA,0xCE,0x0A,0x00,0x00,0x00,0x00};
       std::fstream fout("header.raw", std::ios::out | std::ios::binary);
       fout.write((char*)data_new, sizeof data_new);
       return 0;
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Well, I'll try it that way, but I didn't think it mattered. I have this prog. up n' running using an exterior data file but I hate that method. *dat files wind up in another directory, exe. crashes because of it, you probably know that deal.

    Thanks for the input. If you (or anyone else) can offer any other advice, feel free.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Stumbled on a quick solution;

    Code:
    string zero;
    
       zero.insert(zer1.end(),0);
       zero.insert(zer2.begin(),0);

    It does precisely what I needed, so I'll go with it....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  2. Need help with project
    By chrisa777 in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2006, 05:01 PM
  3. Replies: 1
    Last Post: 02-03-2005, 03:33 AM
  4. hexadecimal values for printer with BIOS
    By frenchfry164 in forum Tech Board
    Replies: 1
    Last Post: 01-17-2003, 07:02 PM
  5. How to read in empty values into array from input file
    By wpr101 in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2002, 10:59 PM