因此,假设您有一个C程序,在将控制权返回给int foo()
之前先调用函数main()
,然后main()
使用puts()
写入控制台。
防止puts
写入控制台有哪些方法?
您获得的唯一#includes
是stdio和stdlib。您无法触摸main()
中的任何代码,只能触摸foo()
。
#include <stdio.h>
#include <stdlib.h>
unsigned int foo()
{
//Your code here
return 0;
}
int main()
{
foo();
puts("If you are reading this you have failed");
return 0;
}
在#include <stdio.h>
#include <stdlib.h>
int main(void)
{
puts("stdout is printed to console");
if (freopen("redir.txt", "w", stdout) == NULL)
{
perror("freopen() failed");
return EXIT_FAILURE;
}
puts("stdout is redirected to a file"); // this is written to redir.txt
fclose(stdout);
}
处,放置//Your code here
。