相同代码上的输出序列之间的差异;\n〃;
#include<stdio.h>
#include<errno.h>
#include<string.h>
int main()
{
FILE * fp;
fp = fopen("GeeksForGeeks", "/root/C");
printf("Value of error no : %dn", errno);
printf("The error message is : %sn", strerror(errno));
perror("Message from perror.");
return 0;
}
这是我的代码,但当我删除";\n〃;,perror的执行顺序发生了变化。有人能解释一下原因吗?
很可能,stdout
处于行缓冲模式,因此它在n
上刷新,而perror
写入stderr
。
在perror
调用之前添加fflush(stdout);
将修复它。