echo_chenchen 2022-10-20 13:37 采纳率: 80.2%
浏览 20
已结题

这段代码有哪些语法错误吗,



#include<stdio.h>
#include<math.h>
#include<string.h>
int judge(int a, int b, int distance);
struct stu
{
    int numble;
    int ChineseScore;
    int MathScore;
    int EnglishScore;
    int sum;
    char name[];
};
struct stu score[2500];
struct cp
{
    char name1[];
    char name2[];
};
struct cp name[2000];
int main()
{
    int N = 0;
    int count = 0;
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        scanf("%s%d%d%d", score[i].name,&score[i].ChineseScore,//输入名字
            &score[i].MathScore, &score[i].EnglishScore);
        score[i].sum = score[i].ChineseScore + score[i].MathScore + score[i].EnglishScore;
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = i+1; j < N; j++)
        {
            int flag1 = 1,flag2=1,flag3=1,flag4=1;
            flag1 = judge(score[i].ChineseScore, score[j].ChineseScore, 5);
            flag2 = judge(score[i].MathScore, score[j].MathScore, 5);
            flag3 = judge(score[i].EnglishScore, score[j].EnglishScore, 5);
            flag4 = judge(score[i].sum, score[j].sum, 10);
            if (flag1&&flag2&&flag3&&flag4)
            {
                    if (strcmp(score.name[i],score.name[j])>0)
                {
                    strcpy(cp.name1[count],score.name[i]);
                    strcpy(cp.name2[count],score.name[j]);
                }
                    else if (strcmp(score.name[i],score.name[j])<0)
                {
                    strcpy(cp.name2[count],score.name[i]);
                    strcpy(cp.name1[count],score.name[j]);
                }
                count++;
            }

        }
    }
    for(int i=0;i<count;i++)
    {
        printf("%s%s",cp.name1[i],cp.name2[i]);
    }
    return 0;
}
int judge(int a, int b, int distance)
{
    int flag = 1;
    if (abs(a - b) > distance)
        flag = 0;
    return flag;
}

  • 写回答

1条回答 默认 最新

  • 浪客 2022-10-20 13:41
    关注

    结构里的几个name都定义了数组,没写大小。把数组大小补上

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 10月28日
  • 已采纳回答 10月20日
  • 创建了问题 10月20日

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)