writing a file byte by byte

D'Arcy J.M. Cain darcy at druid.uucp
Fri Mar 1 14:35:11 AEST 1991


In article <9527 at hub.ucsb.edu> 6600bori at ucsbuxa.ucsb.edu (Boris Burtin) writes:
>I'm using Turbo C 2.0 and DOS 3.3, and I'm attempting to write 8166 bytes
>to a file (for those who know what I'm talking about, this is a MIDI sysex
>file).  By the MIDIEX standard, this file should be 8166 bytes long, but
>when I write it, it turns out to be some 8300 or so bytes long.  Does anyone
>know how to solve this problem?  Thanks...

There really isn't much information here but I'll make a guess.  How many
of the bytes that you are writing happens to be 0x0a?  By any chance 234?
maybe you are opening the file as "w" instead of "wb".  The default with
MSDOS is to open the file in text mode and that means that line feeds are
converted to CR/LF pairs.  If you are writing binary data you should always
open a file in binary mode even if you are working on a Unix system or some
other system where this doesn't matter.  It saves you heartaches when you
decide to port the code and also serves as sort of a comment about how you
intend to treat the data in the file.  Note that on systems where the "b"
flag is not needed the flag is ignored.

If this is not your problem please give more details and if possible some
sample code that exhibits the problem.

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   There's no government
West Hill, Ontario, Canada         |   like no government!
+1 416 281 6094                    |



More information about the Comp.lang.c mailing list