- 1 /*************************************************************************
- 2 > File Name: clearing.c
- 3 > Author: Mr.Yang
- 4 > Purpose:演示流中剩余字符的解决方法
- 5 > Created Time: 2017年05月20日 星期六 14时23分25秒
- 6 ************************************************************************/
- 7
- 8#include
- 9#include
- 10
- 11 voidclear_kb(void);
- 12
- 13 intmain(void)
- 14 {
- 15 intage =0;
- 16 charname[50];
- 17
- 18printf("Enter your age:");
- 19scanf("%d",&age);
- 20 //clear_kb();
- 21fflush(stdin);//此处为什么加入后编译运行时没有效果?
- 22
- 23printf("Enter your name:");
- 24scanf("%s",name);
- 25
- 26printf("你的年龄是:%d,你的名字是:%s\n",age,name);
- 27 return 0;
- 28 }
- 29
- 30 voidclear_kb(void)
- 31 {
- 32 charclear[1000];
- 33fgets(clear,1000,stdin);
- 34}
来源: http://www.bubuko.com/infodetail-2079191.html