注册 登录
编程论坛 C语言论坛

麻烦大佬指出为啥输出乱码

Knightl8 发布于 2020-03-17 11:32, 1615 次点击
题目
[附件]
只有本站会员才能查看附件,请 登录
[/附件]
我的代码
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

struct shot
{
    char id[4];
    int x;
    int y;
};
int main(void)
{

    struct shot people[10000];
    float max=0,min=0;
    char *maxindex=NULL,*minindex=NULL;

    int num;
    scanf("%d",&num);

    for(int i=0;i<num;i++)
    {
        scanf("%s %d %d",people[i].id,&people[i].x,&people[i].y);
        float score = sqrt(people[i].y*people[i].y+people[i].x*people[i].x);
        if(i==0)
        {
            min = score;
            minindex =people[i].id;
        }
        if((float)score>max)
        {
            max = score;
            maxindex = people[i].id;
        }
        if(score<=min)
        {
            min = score;
            minindex = people[i].id;
        }
        

    }

    printf("%s %s\n",minindex,maxindex);

    system("pause");
    return 0;

}


乱码:
只有本站会员才能查看附件,请 登录



[此贴子已经被作者于2020-3-17 11:33编辑过]

2 回复
#2
forever742020-03-17 12:15
因为char id[4]没地方放字符串结束符
#3
Knightl82020-03-17 14:02
回复 2楼 forever74
好的,0分贴谢谢了
1