标题:expected 'struct context *' but argument is of type 'struct context'是 ...
只看楼主
lbgandthesun
Rank: 2
等 级:论坛游民
帖 子:7
专家分:34
注 册:2014-9-13
 问题点数:0 回复次数:2 
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
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
得分:0 
乱写星号,实参与形参类型不符。

授人以渔,不授人以鱼。
2014-09-13 22:07
erty1001
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:331
专家分:1433
注 册:2014-8-31
得分:0 
简单说说:
      else p=(struct context*)add(*p);
你看这里  add()里面的参数 是struct context *add(struct context* p)
应该是一个指针,
而你给这个参数是(*p)是一个变量
至少应该改成  else p=(struct context*)add(p);

至于其他的错误,由于代码过长 暂时不考虑啦
2014-09-13 22:55



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




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

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