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 <stdio.h>
9 #include <stdlib.h>
10
11 void clear_kb(void);
12
13 int main(void)
14 {
15 int age = 0;
16 char name[50];
17
18 printf("Enter your age:");
19 scanf("%d",&age);
20 //clear_kb();
21 fflush(stdin);//此处为什么加入后编译运行时没有效果?
22
23 printf("Enter your name:");
24 scanf("%s",name);
25
26 printf("你的年龄是:%d,你的名字是:%s\n",age,name);
27 return 0;
28 }
29
30 void clear_kb(void)
31 {
32 char clear[1000];
33 fgets(clear,1000,stdin);
34 }