qq_44884197 2019-05-18 11:47 采纳率: 66.7%
浏览 1252
已采纳

如何让结果在主函数输出

求助如何用指针让结果(一个字符串中的字母,数字,空格,和其他字符)在主函数输出。

#include<stdio.h>
int main()
{  
    void count(char str[100]);
    char str[100];
    gets(str);
    count(str); 
}
void count(char str[100])
{
    int*l,*d,*s,*o;
    int letter=0,digit=0,space=0,other=0;
    int i;
    for(i=0;str[i]!=0;i++)
    {
    if((str[i]>'A'&&str[i]<'Z')||(str[i]>'a'&&str[i]<'z'))
        letter++;
    else if(str[i]>'0'&&str[i]<'9')
        digit++;
    else if(str[i]==32)
        space++;
    else other++;
    }
    l=&letter;
    d=&digit;
    s=&space;
    o=&other;
    printf("%d,%d,%d,%d",*l,*d,*s,*o);
}

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-05-18 11:57
    关注
    // Q762150.cpp : This file contains the 'main' function. Program execution begins and ends there.
    //
    
    #include<stdio.h>
    int main()
    {
        void count(char str[100], int* l, int* d, int* s, int* o);
        char str[100];
        gets_s(str);
        int l, d, s, o;
        count(str, &l, &d, &s, &o);
        printf("%d,%d,%d,%d", l, d, s, o);
    }
    void count(char str[100], int *l, int *d, int *s, int *o)
    {
        int letter = 0, digit = 0, space = 0, other = 0;
        int i;
        for (i = 0; str[i] != 0; i++)
        {
            if ((str[i] > 'A' && str[i] < 'Z') || (str[i] > 'a' && str[i] < 'z'))
                letter++;
            else if (str[i] > '0' && str[i] < '9')
                digit++;
            else if (str[i] == 32)
                space++;
            else other++;
        }
        *l = letter;
        *d = digit;
        *s = space;
        *o = other;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog