Date: 26 Mar 1993 17:17:51 -0800 (PST) From: Gregory Eakin Subject: Re: Writting Binary files To: djgpp AT sun DOT soe DOT clarkson DOT edu On March 26, 1993, Lenny A. Krieg 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