分别用C语言指针和函数:输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数

如题所述

第1个回答  2011-04-13
#include <stdio.h>
#define N 100
void main()
{
void count_D_E(char a[]);
char a[N];
printf("Please input a string:\n");
gets(a);
count_D_E(a);
}
void count_D_E(char *a)
{
int i=0;
int S1=0,S2=0,S3=0,s4=0;
while(a[i]!='\0')
{
if(a[i]<='z'&&a[i]>='a'||a[i]<='Z'&&a[i]>='A')
S1++;
else if(a[i]<='9'&&a[i]>='0')
S2++;
else if(a[i]==' ')
S3++;
else s4++;
i++;

}
printf("%d,%d,%d,%d",S1,S2,S3,s4);
}本回答被提问者采纳
第2个回答  2011-04-20
void main()
{
//char a[50];
int letter=0,number=0,blank=0,other=0;
//int i;
//gets(a);
char c; 用来读取每个字符
while ((c=getchar())!='\n') //基本就是修改的这句,当读入的是回车即为结束运算
//for(i=0;i<50,a[i]='\n';i++)
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
letter++;
else if(c>='0'&&c<='9')
number++;
else if(c==' ')
blank++;
else other++;
}
printf("letter=%d,number=%d,blank=%d,other=%d",letter,number,blank,other);
}
程序已经验证过,可以执行哦~~~
另外,团IDC网上有许多产品团购,便宜有口碑

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网