how C output LF to stdout without being changed to CR LF?

前端 未结 3 711
后悔当初
后悔当初 2020-12-11 05:15

On Windows this

#include 

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

outp

3条回答
  •  既然无缘
    2020-12-11 06:00

    #ifdef _WIN32
    #include 
    #include 
    #endif
    
    #ifdef __BORLANDC__
    #define _setmode setmode
    #endif
    
    #include 
    
    static void binary_stdout(void) {
    #ifdef _WIN32
        _setmode(_fileno(stdout), _O_BINARY);
    #endif
    }
    
    int main(void) {
        binary_stdout();
        printf("\n");
        return 0;
    }
    

提交回复
热议问题