C语言字符串指针参数传递的问题

问题遇到的现象和发生背景

在屏幕上输入若干个10进制整数数字,用空格分开,以回车结束。

  1. 实装一个子函数int get_count(const char* pInput, const int nLen),获得字符串中数字的个数。
  2. 根据get_count的返回值,动态申请内存,用来准备存放所有数字。
  3. 实装一个子函数int calc(const char* pInput, const int nLen, float* pAvg, int* pAsc), 其中,函数返回值是所有数字相加的总数,pAvg是输出参,用来存放所有数字的平均值,pAsc是输出参,用来存放升序排列后的所有数字。
  4. 在屏幕上打印出这组数字的最大值,最小值,总数,平均值(2位小数),所有数字的升序排列,所有数字的降序排列。
  5. 额外的要求,除i,j外,main函数与子函数中不得出现相同的变量名。

例:
Please input numbers, conject them with blank:
180 9 0 244 -3 88 5000 22
MAX = 5000
MIN = -3
SUM = 5540
AVG = 692.50
ASC = -3 0 9 22 88 180 244 5000
DESC = 5000 244 180 88 22 9 0 -3

就是要先用字符串读入,然后根据空格拆分出所有整数呗

#include<stdio.h>
#include<string.h>
 
int get_count(const char* pInput, const int nLen)
{
    int count = 0;
    for(int i=0;i<nLen;i++)
        if(pInput[i] == ' ')
            count++;
    return count+1;
}

int calc(const char* pInput, const int nLen, float* pAvg, int* pAsc)
{
    int sum = 0,n = 0,j=0,num = 0,k=0,t,flag = 1;
    for(int i=0;i<nLen;i++)
    {
        if(pInput[i] == '-')
            flag = 0;
        else if(pInput[i] != ' ')
            n = n*10 + pInput[i] - '0';
        else
        {
            num++;
            if(flag == 0)
                pAsc[j] = -n;
            else
                pAsc[j] = n;
            sum += pAsc[j];
            j++;
            n=0;
            flag = 1;
        }
    }
    if(flag == 0)
        pAsc[j] = -n;
    else
        pAsc[j] = n;
    sum += pAsc[j];
    j++;
    for(int i=0;i<j-1;i++)
    {
        for(k=0;k<j-1-i;k++)
        {
            if(pAsc[k] > pAsc[k+1])
            {
                t = pAsc[k];
                pAsc[k] = pAsc[k+1];
                pAsc[k+1] = t;
            }
        }
    }

    *pAvg = sum/(num+1.0);
    return sum;
}

int main()
{
    char s[100];
    printf("Please input numbers, conject them with blank:\n");
    gets(s);
    int len = strlen(s);
    int count = get_count(s,len);
    int *data = (int*)malloc(sizeof(int)*count);
    float avg;
    int sum = calc(s,len,&avg,data);
    printf("MAX = %d\n",data[count-1]);
    printf("MIN = %d\n",data[0]);
    printf("SUM = %d\n",sum);
    printf("AVG = %.2f\n",avg);
    printf("ASC = ");
    for(int i=0;i<count;i++)
        printf("%d ",data[i]);
    printf("\n");
    printf("DESC = ");
    for(int i=count-1;i>=0;i--)
        printf("%d ",data[i]);
    return 0;

}

你的问题是什么,我没有看出来

很简单得,主要是利用几个函数,我看上面有哥们写了,我就不写了,最主要还是自己完整写一遍比较好