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



#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.");
}

structcmp方法没返回值
函数没声明

修改在注释里

#include <stdio.h>
#include <string.h>
struct emp
{
    char n[20];
    int age;
};
int structcmp (struct emp x, struct emp y)//返回值类型int 
{
    if(strcmp(x.n , y.n)==0&&x.age == y.age)//strcmp()来比较字符串是否相等
        return 0;
    return 1;
}
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.");
}