代码如下所示:
#include<stdio.h>
#include<unistd.h
int main()
{
char buf[21]="";
setbuffer(stdout, buf, 20);
while(1)
{
fprintf(stdout, "hello");
fprintf(stderr, "world");
sleep(1);
}
return 0;
}
输出为(为方便查看已换行):
hello
worldworldworldworldworld
hellohellohellohellohello
worldworldworldworldworld
hellohellohellohellohello
...
问题:
一开始为什么会输出一个 “hello”?
#include<stdio.h>
#include<unistd.h
int main()
{
char buf[21]="";
setbuffer(stdout, buf, 20);
while(1)
{
fprintf(stdout, "hello");
fprintf(stderr, "world");
sleep(1);
}
return 0;
}
输出为(为方便查看已换行):
hello
worldworldworldworldworld
hellohellohellohellohello
worldworldworldworldworld
hellohellohellohellohello
...
问题:
一开始为什么会输出一个 “hello”?