//编写一个函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其他字符的个数,//在主函数中输入字符串以及输出上述的结果。#include <stdio.h>#include <string.h>//定义全局变量int word, number, space, other;int main() {void tongji(char a[]);//输入字符串char str[80];//scanf("%s", str);gets(str);word = 0;number = 0;space = 0;other = 0;tongji(str);printf("%d,%d,%d,%d", word, number, space, other);return 0;}void tongji(char a[]) {int i;int k=strlen(a);for (i = 0; i<k; i++) {if ((a[i] >= 'A' && a[i] <= 'Z') || (a[i] >= 'a' && a[i] <= 'z')) word++;else if (a[i] >= '0' && a[i] <= '9') number++;else if (a[i] == ' ') space++;else other++;}}
【C】编写一个函数 由实参传来一个字符串 统计此字符串中字母 数字 空格和其他字符的个数 在主函数中输入字符串以及输出上述的结果。