473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

0D after 0A in hex when writing a binary file

Hello,

I am writing out a binary file. I figured that the number "10" is
automaticaly converted to "OD OA" instead of "OD". "OD" and "OA" are
line feed and carriage return.

I know it does that if the file is opened in something else than in
binary mode. But in my example below, the file is really opened in
binary.

I am compiling the file with VC++.NET
I am using 010 Editor to edit the binary file.

Thanks for your help,

Ctest2App::Ctest2App()
{
long i;
long Size=10;
LONG len=1;

ofstream *BinFile; // The acq file streams
PUCHAR *buf=new PUCHAR[Size];
BinFile = new ofstream("out.bin");
for (i =0; i < Size; i++) {
buf[i] = new UCHAR[len];
buf[i][0]=10;
}
for (i =0; i < Size; i++) BinFile->write((char *) buf[i], len);
}

Jul 22 '05 #1
3 5447
Romain wrote:
I am writing out a binary file. I figured that the number "10" is
automaticaly converted to "OD OA" instead of "OD". "OD" and "OA" are
line feed and carriage return.
Actually, reverse. "0D" and "0A" are carriage return and line feed
(and those are zeros and not Os in the numbers).
I know it does that if the file is opened in something else than in
binary mode. But in my example below, the file is really opened in
binary.
Nope.

I am compiling the file with VC++.NET
I am using 010 Editor to edit the binary file.

Thanks for your help,

Ctest2App::Ctest2App()
{
long i;
long Size=10;
LONG len=1;

ofstream *BinFile; // The acq file streams
PUCHAR *buf=new PUCHAR[Size];
BinFile = new ofstream("out.bin");
What makes you think this is opening as binary? The fact that you made
the name to contain letters 'b', 'i', and 'n', is definitely not enough.
Do

BinFile = new ofstream("out.bin", ios::binary);



for (i =0; i < Size; i++) {
buf[i] = new UCHAR[len];
buf[i][0]=10;
}
for (i =0; i < Size; i++) BinFile->write((char *) buf[i], len);
}


Victor
Jul 22 '05 #2

"Romain" <ro**********@voila.fr> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello,

I am writing out a binary file. I figured that the number "10" is
automaticaly converted to "OD OA" instead of "OD". "OD" and "OA" are
line feed and carriage return.

I know it does that if the file is opened in something else than in
binary mode. But in my example below, the file is really opened in
binary.
Really? Isn't the default mode text? The code below doesn't specify binary
anywhere.

I am compiling the file with VC++.NET
I am using 010 Editor to edit the binary file.

Thanks for your help,

Ctest2App::Ctest2App()
{
long i;
long Size=10;
LONG len=1;

ofstream *BinFile; // The acq file streams
PUCHAR *buf=new PUCHAR[Size];
BinFile = new ofstream("out.bin");
Why are you using a pointer here? And where's the specifier saying it
should be binary? I think this should be:

ofstream BinFile("out.bin",ios_base::binary);


for (i =0; i < Size; i++) {
buf[i] = new UCHAR[len];
buf[i][0]=10;
}
for (i =0; i < Size; i++) BinFile->write((char *) buf[i], len);
}


(Any reason you're dynamically allocating these buffers? Just curious. If
you need dynamic sizing, you might consider using the string class instead
of dynamic arrays.)

-Howard

Jul 22 '05 #3

"Romain" <ro**********@voila.fr> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hello,

I am writing out a binary file. I figured that the number "10" is
automaticaly converted to "OD OA" instead of "OD". "OD" and "OA" are
line feed and carriage return.
The number 10 is the encoding for the 'line feed' character in
ASCII. But note that C++ does not mandate a particular character
set.

Also, such conversions when doing file i/o are platform-specific.
You're describing what happens for MSDOS and MS-Windows, but
C++ can be run with many other operating systems as well, some
of which have different translations, or none at all.

Also, your "OD OA" above is using an upper case letter 'O',
but those should be the digit zero (0).

I know it does that if the file is opened in something else than in
binary mode.
On some platforms. Also note that in C++ there is only one
'something else' besides 'binary mode', which is 'text mode'.
Streams opened in 'text mode' will possibly induce these
translations, *for some platforms*, not all.
But in my example below, the file is really opened in
binary.
Um, no it is not. The default mode for a stream is text.

I am compiling the file with VC++.NET
I am using 010 Editor to edit the binary file.

Thanks for your help,

Ctest2App::Ctest2App()
{
long i;
long Size=10;
LONG len=1;

ofstream *BinFile; // The acq file streams
This is not a stream object, but a pointer to one.
Why are you using a pointer?
PUCHAR *buf=new PUCHAR[Size];
BinFile = new ofstream("out.bin");
This opens the stream in text mode, which will cause translations
on some platforms. BTW why are you dynamically allocating the
stream instead of simply defining one, e.g.

ofstream ofs("out.bin");

You also failed to check whether the open succeeded or failed.
If it failed, any subsequent attempts to use the stream will
certainly fail as well.


for (i =0; i < Size; i++) {
buf[i] = new UCHAR[len];
I don't understand this need you seem to have to dynamically
allocate things. This only makes the code unnecessarily
complex and harder to maintain.
buf[i][0]=10;
}
for (i =0; i < Size; i++) BinFile->write((char *) buf[i], len);
}


Which C++ book(s) are you reading?

-Mike
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: letkok | last post by:
Help! When I run the VB program in test mode while looking at the code, it functions correctly and creates the desired file. When I compile it on the server and try to have it run from the...
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
1
by: Mikael Petterson | last post by:
Hi, I am using xsl to create a number of java files. If I discover a certain information in my input file (xml) I must report it to the user similair to " Error reported when creating class...
2
by: DBC User | last post by:
Hi Sharpies, I have a C program I am converting it into C#. Everything is fine except this process creates a 6K byte binary file. This file initially filled with 6K null and then start...
4
by: Greg | last post by:
Using the HttpWebRequest I'm downloading a PDF file and am trying to save it to the hard drive, but it keeps ending up corrupt (according to adobe acrobat). I know the PDF file isn't corrupt...
7
by: W. Jordan | last post by:
Hello, I am using Response.WriteFile (filename) to write a file that on the server to my web client. I discover that the while a client request a big file, for example, a 14m-bytes one, the...
2
by: John Salerno | last post by:
If I read a string that contains a newline character(s) into a variable, then write that variable to a file, how can I retain those newline characters so that the string remains on one line rather...
13
by: Speed | last post by:
Hi, I have a 57000 bit long binary number and I want to save it to a file. At the moment I am using an unsigned char array to store the array and then fwrite to store it as follows. fwrite(...
4
by: Thomi Aurel RUAG A | last post by:
Hy Mike Thanks for your links, unfortunately they weren't very usefull for my specific problem. Hy Grant Edwards Thanks for your hints. A simplified test programm to compare the function for...
9
by: Ron Eggler | last post by:
Hi, I would like to write binary data in a file i open (ofstream) with ios::binary but it keeps failing and it gives me a segmentation fault. What I'm exactly doing: if (isBinary == true) {...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.