Mail Archives: djgpp/1993/03/26/20:29:02
On March 26, 1993, Lenny A. Krieg <LKRIEG AT dpc2 DOT hdos DOT hac DOT com> writes
> . . . The second
> program, PROGRAM 2, opens a BINARY file using OFSTREAM and attempts to
> write out 1600 unsigned ASCII 255 values. The file produced is empty.
> The third program, PROGRAM 3, opens a BINARY file using OFSTREAM and
> attempts to write out 1600 unsigned ASCII 254 values. It works fine.
>
> Am I doing something wrong or is there a problem with writing BINARY
> files that contain ASCII 255? What is magical about ASCII 255? Does
> anyone know a solution using OFSTREAM? . . .
No, the problem is OFSTREAM converts your (unsigned char) to a
(signed char), then a (signed int). So when the the conversion
of 0xFF to 0xFFFFFFFF occures, it is treated as the EOF flag. That's
why your file is empty.
I have two ideas:
1) Tell OFSTREAM about unsigned chars, (ugh :={).
or
2) replace the code
binfile << ( unsigned char ) data [ k ];
with
binfile._strbuf->sputc( ( unsigned char ) data [ k ]); // KLUDGE!
Greg Eakin, Student
California State Univeristy, Fullerton
xgeakin AT fullerton DOT edu
- Raw text -