怎样维修燃气灶视频:题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

来源:百度文库 编辑:高校问答 时间:2024/04/16 12:40:02
#include "stdio.h"
#include "conio.h"
main()
{
char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
getch();
}

while((c=getchar())!='\n')这一句实现的是什么呀

意思是,字符变量C从键盘取值,如果C的值只要不是回车While下面的循环就一直运行。

getchar()是接受输入,整句是判断输入是否结束,\n指回车键,回车即输入结束