Description
用指针编写一个程序,输入字符串后,统计其中各种字符的个数,输出其中大小写字母,数字,以及其他字符的个数。
主函数已经给出,请编写统计字符种类函数。
Input
一串字符串
Output
该字符串中大小写字母,数字,以及其他字符的个数,最后输出总字符串长度。
Sample Input**
I play LOL for 3 years.
Sample Output
4
12
1
6
23
代码:、
/*
Copyright (c) 2016,烟台大学计算机与控制工程学院
All Rights Reserved.
文件名称: 统计字符串种类
作 者:胡寅生
完成日期:2016年12.13
版 本 号;v1.0
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[100];
gets(str);
char *ptr=str;
void fuction(char *);
fuction(ptr);
return 0;
}
void fuction(char *str)
{
int a=0,b=0,c=0,d=0,i=0;
while(str[i]!='\0')
{
if(str[i]>='A'&&str[i]<='Z')
a++;
else if(str[i]>='a'&&str[i]<='z')
b++;
else if( str[i]>='0'&&str[i]<='9')
c++;
else
d++;
i++;
}
printf("%d\n%d\n%d\n%d\n%d\n",a,b,c,d,i);
}
运行结果: