这道题用c语言程序编写

来源:百度知道 编辑:UC知道 时间:2024/06/16 00:24:33
1.从键盘输入一行字符(文本),统计其中大写字母、小写字母、空格、
数字和其它字符的数目。
用c语言如何编写啊,急急急!!!

#include <stdio.h>
#include <stdlib.h>

int main()
{
int n_lower=0,n_upper=0,n_num=0,n_space=0,n_other=0;
char s[255];
int i;
char c;

printf( "Please input the string: \t" );
gets(s);

i = 0;
while( s[i] != '\0' ) {
c = s[i];
if( c >= 'a' && c <= 'z' )
n_lower++;
else if( c >= 'A' && c <= 'Z' )
n_upper++;
else if( c >= '0' && c <= '9' )
n_num++;
else if( c == 0x20 )
n_space++;
else {
n_other++;
}

i++;
}

printf( "The number of lower character(s) is %d\n", n_lower );
printf( "The number of upper character(s)