温水和彦 2023-12-23 14:42 采纳率: 50%
浏览 6

高玩看看哪里错了求答案

/编写程序,输入一字符串输出此字符串中字母、数字、空格和其他字符的个数。
要求:
(1)编写一个函数实现上述统计功能:由实参传来一个字符串,
统计此字符串中字母、数字、空格和其他字符的个数。
(2)在主函数中输出上述统计结果。
提示:借助全局变量
/


#include <stdio.h>

void tongji(char s[],int *A,int *B,int *C,int *D);
int main()
{
    char s[20];
    int a, b, c, d;
    int*A=&a, *B=&b, *C=&c, *D=&d;

    printf("请输入一字符串\n");
    gets(s);
    tongji(s,A,B,C,D);
    printf("统计此字符串中字母、数字、空格和其他字符的个数\n");
    printf("分别为:%d,%d,%d,%d\n",*A,*B,*C,*D);
}
void tongji(char s[], int* A, int* B, int* C, int* D)
{
    int i = 0;
    int a=0, b=0, c=0, d=0;
    for (i=0;s[i]!='\0';i++)
    {
        if (s[i]>='a'&&s[i]<='z'||s[i]>= 'A'&&s[i]<='Z') a++;
        else if (s[i]>='0'&&s[i]<='9') b++;
        else if (s[i]==' ') c++;
        else d++;
    }
    *A=a;
    *B=b;
    *B=c;
    *D=d;
}
  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 创建了问题 12月23日