1.getchar的使用
(1)
#include<stdio.h>
int main()
{
int ret = 0;
int ch = 0;
char password[20] = {0};
printf("请输入密码:>");
scanf("%s",password);
while((ch=getchar()) != '\n')//将缓冲区内容全部读取
{
;
}
printf("请确认(Y/N):>");
ret = getchar();
if(ret == 'Y')
{
printf("确认成功\n");
}
else
{
printf("放弃确认\n");
}
return 0;
}
(2)
#include<stdio.h>
int main()
{
while((ch = getchar()) != EOF)
{
if(ch < '0' || ch > '9')
continue;
putchar(ch);//只打印'0'~'9'的字符
}
return 0;
}
2.循环结构
(1)while循环
#include<stdio.h>
int main()
{
int i = 0;//初始化
while(i<10)//判断
{