C - printf() 不工作,但 put() 工作正常

标签 c

void read_class_information(head* beginning, int scale_type) {
    puts("hello");
    // printf("hello");
}

我有一个由 main 调用的简单函数,并且 stdout 的 printf() 和 fprintf() 在其中不起作用。另一方面,puts() 工作得很好。我在 printf() 调用时没有打开任何文件,也没有任何错误。对可能出现的问题有什么建议吗?谢谢。

最佳答案

因为printf()不会自动刷新输出流。另一方面,puts() 在传递的字符串末尾添加一个新行'\n'。所以它可以工作,因为 '\n' 刷新了 stdout

尝试

printf("hello\n");

或者,显式刷新stdout

fflush(stdout);

就在 printf() 语句之后。

关于C - printf() 不工作,但 put() 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44209950/

相关文章:

c - 归并排序的应用

c - 验证整数输入

CMOCKA/链接器 : 'wrap' ping lots of functions

c - 使用 MPLAB X IDE C18 编译器编译我的 Microchip PIC18f4550 USB 项目时出现问题。编译器一直高亮显示 "syntax error"并且不会编译

c++ - 在 android 内核开发 linux 中使用蓝牙

c - 段错误 11 和在 c 中创建/打印字符串数组时出现问题

c - 我向不存在的IP发送tcp syn数据包,但没有得到响应

c - 使用 GDAL C API 编写栅格

c++ - 无符号长整型

c - 段错误(核心转储)——如何修复我的代码?