Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Controlling Binary and Text Modes
◄Up► ◄Contents► ◄Index► ◄Back►
────────────────────────────────────────────────────────────────────────────
Most C programs use one or more data files for input and output.
Data files are ordinarily processed in text mode, in which
carriage-return──line-feed (CR-LF) combinations are translated
into a single line-feed (LF) character upon input. LF characters
are translated to CR-LF combinations upon output.
In some cases, you may want to process files without making these
translations. In binary mode, CR-LF translations are suppressed.
Standard library routines, such as fopen or open, give you the
option of overriding the default mode when you open a particular
file. You can also change the default mode for an entire program
from text to binary mode. Do this by linking your program with the
file BINMODE.OBJ, which is supplied as part of your C compiler
software. Simply add the path name of BINMODE.OBJ to the list of
object file names when you link your program. For example,
cl myprog.c binmode.obj /link /NOE
When you link with BINMODE.OBJ, all files opened in your program
default to binary mode, with the exceptions of stdin, stdout, and
stderr. However, linking with BINMODE.OBJ does not force you to
process all data files in binary mode. You still have the option
of overriding the default mode when you open the file.
Use the setmode library function to change the default mode of
stdin, stdout, or stderr from text to binary, or the default mode
of stdaux or stdprn from binary to text. The setmode function can
change the current mode for any file and is primarily used for
changing the modes of stdin, stdout, stderr, stdaux, and stdprn,
which are not explicitly opened by users.
-♦-