C如何在不更改为CR LF的情况下将LF输出到stdout? [英] how C output LF to stdout without being changed to CR LF?

查看:71
本文介绍了C如何在不更改为CR LF的情况下将LF输出到stdout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows上

#include <stdio.h>

int main() { 
    putc('A',stdout);
    putc('\r',stdout); 
    putc('\n',stdout);
}

输出

A<CR><CR><LF>

如何在不自动转换为CR LF的情况下仅将LF字符写入标准输出?

How to write just LF char to stdout without automatic conversion to CR LF?

我需要它来使简单的套接字流读取器变为stdout. 我试过了CodeGear的bcc32,mingw,tinycc都产生相同的结果,将putc更改为putchar,fputc,fwrite也无济于事.

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.

推荐答案

MSVC解决方案是:

The MSVC solution is:

#include <io.h>
#include <fcntl.h>
...
_setmode(1,_O_BINARY)

其他运行时可能会提供C99解决方案或替代方法.我相信setmode([file number],O_BINARY)起源于Borland Turbo C,并且其他用于MS-DOS和Windows的编译器都模仿了它.完成_前缀以保持命名空间整洁,某些编译器中可能不存在此前缀.

Other runtimes may provide the C99 solution or an alternate way. 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.

这篇关于C如何在不更改为CR LF的情况下将LF输出到stdout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆