1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 【C】编写一个函数 由实参传来一个字符串 统计此字符串中字母 数字 空格和其他字

【C】编写一个函数 由实参传来一个字符串 统计此字符串中字母 数字 空格和其他字

时间:2023-06-27 14:03:59

相关推荐

【C】编写一个函数 由实参传来一个字符串 统计此字符串中字母 数字 空格和其他字

//编写一个函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其他字符的个数,//在主函数中输入字符串以及输出上述的结果。#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】编写一个函数 由实参传来一个字符串 统计此字符串中字母 数字 空格和其他字符的个数 在主函数中输入字符串以及输出上述的结果。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。