- 论坛徽章:
- 0
|
楼住,运行下面的代码
#include<stdio.h>
#include <unistd.h>
int main()
{
char user[100];
char oldpasswd[100];
char newpasswd[100];
printf("User name:");
//fflush(stdout);
//gets(user);
sleep(2);
printf("Old password:");
//fflush(stdout);
//gets(oldpasswd);
sleep(2);
printf("New password:");
//fflush(stdout);
//gets(newpasswd);
sleep(2);
//printf("---\n%s\t%s\t%s\t",user,oldpasswd,newpasswd);
}
可以看出不能没有fflush(),最后得出结论好像是因为gets()的原因吧~可能是因为调用gets()用到终端,所以先把与终端关联的文件(stdin,stderr,stdout)先冲刷一下。程序在退出的时候先冲刷缓冲区,所以会有最后的输出。各人愚见阿~~忘高人指点一下 |
|