On Windows this
#include <stdio.h>
int main() {
putc('A',stdout);
putc('\r',stdout);
putc('\n',stdout);
}
outputs
A<CR><CR><LF>
How to write just LF char to stdout without automatic conversion to CR LF?
I need it to make simple socket stream reader to stdout. I've tried bcc32 from CodeGear, mingw, tinycc all yield same result, changing putc to putchar, fputc, fwrite doesn't help either.
The MSVC solution is:
#include <io.h>
#include <fcntl.h>
...
_setmode(1,_O_BINARY)
Other runtimes may provide the C99 solution or an alternate way. EDIT: I believe setmode([file number],O_BINARY)
originated on Borland Turbo C, and other compilers for MS-DOS and Windows imitated it. The _ prefix is done to keep the namespace clean, and may not be present on some compilers.