有没有一种方法可以在不使用任何宏的情况下有条件地使所有 printf 语句静音?我想在不触及现有代码的情况下完成静音,但在我的模块中添加一行,这将简单地禁用源代码中已经存在的所有 printf。
谢谢!
最佳答案
如果你想通过printf
、puts
、putchar
等方式使所有输出到stdout
的输出无效,你可以使用 freopen(3)
将它重定向到一个位桶,例如:
// On Unix and Unix-like systems:
freopen("/dev/null", "w", stdout);
// On Windows:
freopen("NUL", "w", stdout);
关于c - 没有宏的静音 printf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11990436/