c语言结构体给歌手分数排序

题目如下第二个:
图片说明

#include<stdio.h>
#include <stdlib.h>

typedef struct result
{
    int num[10];
    int score[10];

}result;

void sorting(result *p)
{
    int i,j,k,temp;
    for(i = 0;i <9;i++)
    {
        k = i;
        for(j = i+1;j<10;j++)
        {
            if(p->score[i] < p->score[j])
            {
                k = j;
            }
        }
        if(k != i)
        {
            temp = p->score[j];
            p->score[j] = p->score[i];
            p->score[i] = temp;
        }
    }
}




int main()
{
    int i;
    result people;
    printf("input:\n");
    for(i = 0;i <10;i++)
    {
        scanf("%d %d",&people.num[i],&people.score[i]);
    }
    sorting(&people.score);
    for(i = 0;i < 10; i++)
    {
        printf(" %d %d\n",i,people.score[i]);
    }


}

请问哪里有问题?

#include <stdio.h>
#include <stdlib.h>

typedef struct result
{
    int num[10];
    int score[10];

}result;

void sorting(result *p)
{
    int i, j, k, temp;
    for (i = 0; i < 9; i++)
    {
        k = i;
        for (j = i + 1; j<10; j++)
        {
            if (p->score[k] < p->score[j])
            {
                k = j;
            }
        }
        if (k != i)
        {
            temp = p->score[k];
            int t1 = p->num[k];
            p->score[k] = p->score[i];
            p->num[k] = p->num[i];
            p->score[i] = temp;
            p->num[i] = t1;
        }
    }
}

int main()
{
    int i;
    result people;
    printf("input:\n");
    for (i = 0; i <10; i++)
    {
        scanf("%d %d", &people.num[i], &people.score[i]);
    }
    sorting(&people);
    for (i = 0; i < 10; i++)
    {
        printf(" %d %d\n", people.num[i], people.score[i]);
    }
}


input:
1 1
2 4
3 2
4 5
5 1
6 7
7 1
8 5
9 9
10 1
9 9
6 7
4 5
8 5
2 4
3 2
7 1
5 1
1 1
10 1
Press any key to continue . . .

类型错误。sorting函数的参数应该是result*型的,而你调用的时候用的是&(people.score),这是一个int (*)[10]型(指向数组的指针)。两个类型不匹配当然会出错了。

修改方法:把主函数中的sorting(&people.score)改成sorting(&people)。

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^