[英]C while infinite loop print error
I made counting little alphabet program. 我计算了一些小字母程序。
However Unintentional result return. 但是,意外结果返回。
I want "Please enter a character " to be printed once per loop. 我希望“请输入一个字符”每个循环打印一次。
#include<stdio.h>
#pragma warning (disable : 4996)
int main() {
char a;
int b = 0, d = 0;
while (1) {
printf("Please enter a character <escape .>");
scanf("%c", &a);
if (a == '.')
break;
if (a <= 'a' || a >='z') {
d = d + 1;
continue;
}
}
printf ("Number of lower case letters %d", d);
getchar(); getchar(); getchar();
return 0;}
Please help me 请帮我
Replace 更换
scanf("%c", &a);
by 通过
scanf(" %c", &a);
Whitespaces were getting consumed by scanf. 空白被scanf占用。 The use of a blank space in scanf() before %c enables omitting whitespaces. 在%c之前在scanf()中使用空格可以忽略空格。
PS To detect lowercase alphabets, the actual if condition should be PS要检测小写字母,实际的if条件应为
if (a >= 'a' && a <='z')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.