石狮爱尚婚礼策划:getchar()问题

来源:百度文库 编辑:中科新闻网 时间:2024/05/13 06:30:13
#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();
}
最后的getch()什么意思?

最后一个getch();是为了让程序在执行后那个printf()以后,停止在那里,不会立刻关掉窗口。

getch()
是让你输入一个字符,而且它又不把他显示`出来
这样就达到了 输入任意键结束的目的