用c语言编写一个程序,统计输入正文中每个数字字符,英文字符和其它字符出现的次数。

来源:百度知道 编辑:UC知道 时间:2024/06/18 03:05:43

需要统计空格么?

英文分大小写么?

如果统计空格、英文大小写请看下面的:
———————————————————————————————
void main()
{int i,s=0,b=0,c=0,d=0,e=0;
char a[50];
gets(a);
for(i=0;i<50;i++)
{
if(a[i]>='A'&&a[i]<='Z')s++;
else
if(a[i]>='a'&&a[i]<='z')b++;
else
if(a[i]>=1&&a[i]<=9)c++;
else
if(a[i]=='')d++;
else e++;}
printf("A-Z:%d a-z:%d 1-9:%d space:%d others:%d ",s,b,c,d,e);
}

//统计函数tongji();即为所求
编译环境,VC6.0,通过,测试无误

#include<stdio.h>
void tongji(char *str,int *ch,int *num,int *other)
{
int i,len=strlen(str);
char temp;
*ch=0;
*num=0;
*other=0;
for(i=0;i<len;i++)
{
temp=str[i];
if((temp>='a' && temp<='z')||(temp>='A' && temp<='Z')) (*ch)++;
else if(temp>='0' && temp<='9') (*num)