解题思路:需要調用函數,而且此函數還需給出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语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:1118 |
震宇大神的杀毒软件 (C语言代码)浏览:1241 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:802 |
C语言训练-排序问题<1> (C语言代码)浏览:601 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:669 |
【出圈】 (C语言代码)浏览:796 |
A+B for Input-Output Practice (III) (C语言代码)浏览:576 |
【亲和数】 (C语言代码)浏览:503 |
C语言训练-求函数值 (C语言代码)浏览:580 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)浏览:2081 |