#include <stdio.h> //预指令
#include <math.h> //运行一些关于数学的函数
#include <string.h> //使用字符串处理函数
//函数声明 全局变量
void array_char_11(char a[]);
//主函数
int main(){
char a[100];
puts("请输入字符:");
gets(a);
array_char_11(a);
return 0;
}
//自定义函数
/*
编写一个函数,由实参传入一串字符,统计这串字符中字母、数字、空格、和其他
字符的个数,在主函数中输入字符串以及输出上述结果。
*/
void array_char_11(char a[]){
int lett=0,dig=0,spac=0,oth=0;
int i;
for( i=0;a[i] !='\0';i++)
{
if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z')){
lett++;
}
else if(a[i]<='9'&&a[i]>='0'){
dig++;
}else if(a[i] == ' '){
spac++;
}else{
oth++;
}
}
printf("letters = %d\n",lett);
printf("digtal = %d\n",dig);
printf("space = %d\n",spac);
printf("others = %d\n",oth);
}
评论10