解题思路:需要調用函數,而且此函數還需給出4個統計值,故需要使用指針,函數只能返回0個或一個值
注意事项:
参考代码:
#include<stdio.h>
void cnt_fun(char total[],int len_0,int *ch,int *num,int *sp,int *oth);
int main(void)
{
char get[100];
int cnt_let=0;
int cnt_num=0;
int cnt_spa=0;
int cnt_oth=0;
int c,len=0;
int i;
while((c=getchar())!='\n'&&c!=EOF){
get[len++]=c;
}
cnt_fun(get,len,&cnt_let,&cnt_num,&cnt_spa,&cnt_oth);
printf("%d %d %d %d",cnt_let,cnt_num,cnt_spa,cnt_oth);
return 0;
}
void cnt_fun(char total[],int len_0,int* ch,int* num,int* sp,int* oth)
{
int i;
int a,b,c,d;
for(i=0;i<len_0;i++){
if(total[i]>='A'&&total[i]<='Z'||total[i]>='a'&&total[i]<='z'){
(*ch)++;//此處注意++的運算等級高於*,故需要加括號,提升優先級
} else if(total[i]>='0'&&total[i]<='9'){
(*num)++;
} else if(total[i]==' '){
(*sp)++;
} else {
(*oth)++;
}
}
}
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:581 |
川哥的吩咐 (C++代码)浏览:1016 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:466 |
【亲和数】 (C语言代码)浏览:541 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:543 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:661 |
字符逆序 (C语言代码)浏览:460 |
字符串输入输出函数 (C语言代码)浏览:2495 |
【魔板】 (C++代码)浏览:1160 |