知道为什么会这样:
#include <stdio.h>
#include <stdlib.h>
int nrpart;
int k;
void main()
{
printf("lol");
freopen("p2.in","r",stdin);
freopen("p2.out","w",stdout);
printf("roar");
}
只输出lol?我其他时候使用过 freopen,但它现在似乎不起作用,我真的不知道为什么。
最佳答案
检查文件 p2.out
。第二次调用 printf
打印的文本在那里,因为您将标准输出重定向到该文件。没有分段违规。不过,这是个好笑话。
关于c - freopen 导致段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13991374/