m0_62267751 2022-01-06 14:49 采纳率: 85.7%
浏览 17
已结题

C语言 出现下列问题 但是不知道怎么改动


#include <stdio.h>

struct emp
{
char n[20];
int age;
};

int main(void)
{
struct emp e1 = {"David", 23};
struct emp e2;
scanf("%s %d", e2.n, e2.age);
if(structcmp(e1, e2) == 0)
printf("Equal structs.");
else
printf("Unequal structs.");
}
structcmp (struct emp x, struct emp y)
{
if(x.n == y.n)
if(x.age == y.age)
return 0;
return 1;
}

img

  • 写回答

3条回答 默认 最新

  • 书山客 2022-01-06 14:59
    关注
    
    
    #include <stdio.h>
    struct emp
    {
        char n[20];
        int age;
    };
    int structcmp(struct emp x, struct emp y)
    {
        if (x.n == y.n)
            if (x.age == y.age)
                return 0;
        return 1;
    }
    int main(void)
    {
        struct emp e1 = { "David", 23 };
        struct emp e2 = { "", 0 };
        scanf("%s %d", e2.n, e2.age);
        if (structcmp(e1, e2) == 0)
            printf("Equal structs.");
        else
            printf("Unequal structs.");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 1月14日
  • 已采纳回答 1月6日
  • 创建了问题 1月6日