中易网

expected 'struct context *' but argument is of type 'struct context'

答案:2  悬赏:30  
解决时间 2021-04-27 03:55
  • 提问者网友:萌萌小主
  • 2021-04-26 16:32
不知道为什么add函数出错,还有底下else p=(struct context*)add(*p);也错,出错信息如下:
incompatible type for argument 1 of 'add'
expected 'struct context *' but argument is of type 'struct context'

#include
#include
struct context
{
struct context *p1;
int n;
char s[10];
int score;
struct context *next;
};

struct context * crea()
{
struct context * p;
p=(struct context *)malloc(sizeof(struct context));
return (p);
}

struct context *add(struct context* p)
{
struct context *p1;
p1=(struct context *)malloc(sizeof(struct context));
p->next=p1;
p1->next=NULL;
return (p1);
}

int main()
{
int n;
struct context * start;
printf("1.创建链表%t2.显示学生信息%t3.学生成绩修改%t4.退出");
scanf("%d",&n);
do {
printf("\n输入序号:");
static struct context* p;
switch(n)
{
case 1:
{
static int n=1;char a;
do
{
if(n==1)
p=crea();
else p=(struct context*)add(*p);
printf("\n输入学生序号:");
scanf("d",p->n);
printf("\n输入学生姓名:");
scanf("%s",p->s);
printf("\n输入学生成绩:");
scanf("%d",p->score);
n++;
printf("a.继续输入%tb.停止输入");
scanf("%c",&a);
}while(a=='a'); break;
}
case 2:{
struct context *p1;
printf("学号 姓名 成绩 ");
p1=start;
while(p1!=NULL)
{
printf("%d %s %d ",p1->n,p1->s,p1->score);
p1=p1->next;
}
} break;

case 3:{
int n;
struct context *p1=start;
printf("输入学生学号:");
scanf("%d",&n);
while((p->n)!=n&&p1!=NULL)
if(p!=NULL)
p1=p1->next;
if(p1!=NULL)
{
printf("修改后成绩:");
scanf("%d",p1->score);
}
else printf("无此考生");

} break;

case 4: exit(0); break;

}
}
while(n!=4);
return 0;}
最佳答案
  • 二级知识专家网友:一只傻青衣
  • 2021-04-26 17:22
struct context *add(struct context* p)//此为函数声明,形参为指针类型
错误的调用 else p=(struct context*)add(*p);// p已是指针类型 static struct context* p;
正确调用 else p=(struct context*)add(p);//去掉*
不懂接着问,改了至少编译通过,你具体业务逻辑我就不知道了
全部回答
  • 1楼网友:开心就好
  • 2021-04-26 18:41
同问。。。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息