标题:expected 'struct context *' but argument is of type 'struct context'是 ...
取消只看楼主
lbgandthesun
Rank: 2
等 级:论坛游民
帖 子:7
专家分:34
注 册:2014-9-13
 问题点数:0 回复次数:0 
expected 'struct context *' but argument is of type 'struct context'是怎么回事
大神帮我看看哪里出错了,add函数定义那里出错,提示信息:[Note] expected 'struct context *' but argument is of type 'struct context'
还有 else p=(struct context*)add(*p);这行出错信息:[Error] incompatible type for argument 1 of 'add'

#include<stdio.h>
#include<stdlib.h>
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;}
搜索更多相关主题的帖子: expected include 提示信息 
2014-09-13 18:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-436042-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.098571 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved