gpt4 book ai didi

c - 如何修复错误 "' strcmp' : different types for formal and actual parameter 1 "?

转载 作者:行者123 更新时间:2023-11-30 19:27:02 25 4
gpt4 key购买 nike

为什么我会收到此错误:

'strcmp': different types for formal and actual parameter 1

?这是我的代码:

typedef struct materie {
char *nume_mat[50];
int nota;
struct materie *next;
} materie;

typedef struct student {
char *nume[50];
char *prenume[50];
struct materie *prim;
struct student *next;
} student;

void adauga_student(student **lista, student *aux)
{
student *q1, *q2;
for (q1 = q2 = *lista;q1 != NULL && strcmp(q1->nume, aux->nume) < 0;q2 = q1, q1 = q1->next);
if (q2 == q1)
{
aux->next = *lista;
*lista = aux;
}
else
{
q2->next = aux;
aux->next = q1;
}
}

最佳答案

这个:

    char *nume[50];

...是一个包含 50 个指针的数组。从语义上来说,这似乎不是您想要的,而且它肯定不是 strcmp() 期望的参数。

也许你想要的是

    char nume[50];

... 50 个字符的数组。作为 strcmp() 的参数,它可以正常工作,因为数组类型的表达式会衰减到指向第一个数组元素的指针。事实上,它是 strcmp 参数的标准形式之一。

您可能希望对其他类似的声明进行相同的更改。

关于c - 如何修复错误 "' strcmp' : different types for formal and actual parameter 1 "?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56296838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com