通过code标准输出重定向到在C文件 [英] Redirecting stdout to a file in C through code
本文介绍了通过code标准输出重定向到在C文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我输出到标准输出。我如何可以重定向通过code一个新的文件?当我们运行程序,我们可以重定向像 ./样品> test.txt的
。我怎么能执行自己的示例程序时,这样做呢? (C编程)
I am outputting to stdout. How can I redirect that to a new file through code? While we run the program we can redirect like ./sample > test.txt
. How can I do this when executing the sample program itself ? (C programming)
推荐答案
您可能需要使用 freopen函数
这是参考示例:
#include <stdio.h>
...
FILE *fp;
...
fp = freopen ("/tmp/logfile", "a+", stdout);
这篇关于通过code标准输出重定向到在C文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文