小程序_统计字符


/****************************************************************
题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
*****************************************************************/

#include <stdio.h>

 

void main(void)
{
int i = 0;
int num = 0;
int character = 0;
int table = 0;
int other = 0;
int size = 0;
char a[255] = {0};
char c ='0';

while(1)
{
memset(a,0,255);
num = 0;
character = 0;
table = 0;
other = 0;
size = 0;


printf("Pls input characters \n");


while((c=getchar())!= '\n')
{

if('0'<=c&&'9'>=c)
{
num++;
}
else if(('a'<=c&&'z'>=c)||('A'<=c&&'Z'>=c))
{
character++;
}
else if(' '==c)
{
table++;
}
else
{
other++;
}
}

printf("num is %d, character is %d, table is %d, other is %d\n", num,character,table,other);
fflush(stdin);
}

posted @ 2016-08-25 17:42  H_amy  阅读(164)  评论(0编辑  收藏  举报