缓冲流自动把getchar()填充

 1 #include"stdio.h"
 2 #include"conio.h"
 3 #include<stdlib.h>
 4 int main()
 5 {
 6     char ch1, ch2;
 7     int i;
 8     printf("请选择相应的操作:\n1:小写转换大写\n2:大写转换小写\n0:输入错误\n");
 9     scanf_s("%d",&i);
10     printf("\n选择菜单i=%d:", i);
11     switch (i)
12     {
13     case 1:
14         printf("请输入小写字母ch1=");
15         getchar();//有缓冲流自动把getchar()填充
16         ch1 = getchar();
17         //getch(ch1);
18         printf("请输入小写字母ch2=");
19         getchar();
20         //scanf_s("%c",ch2);
21         ch2 = getchar();
22         ch1 = ch1 - 32;
23         ch2 = ch2 - 32;
24         printf("ch1=%c\n", ch1);
25         printf("ch2=%c\n", ch2);
26         system("pause");
27         break;
28     case 2:printf("\n请输入大写字母ch1=");
29         getchar();
30         ch1 = getchar();
31         printf("\n请输入大写字母ch2=");
32         getchar();
33         ch2 = getchar();
34         ch1 = ch1 + 32;
35         ch2 = ch2 + 32;
36         printf("ch1=%c\n", ch1);
37         printf("ch2=%c\n", ch2);
38         system("pause");
39         break;
40     default:printf("0:输入错误\n\n");
41     }
42 }

 

posted @ 2013-09-26 18:53  herizai007  阅读(195)  评论(0编辑  收藏  举报