| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 355 人关注过本帖
标题:各位朋友进来帮看看为什么错啊
只看楼主 加入收藏
难的哟
Rank: 2
等 级:论坛游民
帖 子:26
专家分:34
注 册:2012-1-25
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
各位朋友进来帮看看为什么错啊
程序代码:
#include"stdio.h"
#include"stdlib.h"
struct information 
{ 
    long num; //学号//
    char name[6];//姓名//
    struct information *next;/*指向下一个结构体*/
};

int main()
{ char ch;
  struct information fun();//建立链表函数的声明
   struct information shuchu(struct information *);//输出链表函数声明
   struct information *head;
   head=fun();                   //信息提示说这里的=错了,我不太懂额     f:\程序代码\list3.c(15) : error C2115: '=' : incompatible types
   //输入一个y时调用输出链表的函数
   ch=getchar();
   if(ch=='y')
   shuchu(head);
   return 0;

 
  }
//尾插法建立带有头指针的链表
struct information fun()
{
   struct information *last=NULL;//尾指针
   struct information *he;//头指针
   struct information *p,*p1;

   he=p=(struct information *)malloc(sizeof(struct information));//申请空间//
   he->next=NULL;
   last=he->next;
   scanf("%ld",&p->num);//输入学号,姓名//
   scanf("%s",p->name);
   //输入信息直到学号为零//
  while(p->num!=0)
  {  if(he->next==NULL)
         he->next=p;
     else
        last->next=p;
     last=p;
     p1=he;//将p1指向链表的表头
     p=(struct information *)malloc(sizeof(struct information));//申请空间//
     scanf("%ld",&p->num);
     if(p->num==0)
     {free(p);break;}
     scanf("%s",p->name);
     p->next=NULL;
  }
  return p1;//返回p1   这个地方提示说错了  f:\程序代码\list3.c(50) : error C2115: 'return' : incompatible types
}
//链表的遍历
struct information shuchu(struct information *head)

 {while(head!=NULL)
     {printf("%ld,%s\n",head->num,head->name);
      head=head->next;}

 

 }
f:\程序代码\list3.c(15) : error C2115: '=' : incompatible types
f:\程序代码\list3.c(50) : error C2115: 'return' : incompatible types
搜索更多相关主题的帖子: 朋友 姓名 
2012-04-16 21:40
sunqing
Rank: 2
来 自:重庆市
等 级:论坛游民
帖 子:28
专家分:55
注 册:2012-3-8
收藏
得分:20 
#include"stdio.h"
#include"stdlib.h"
struct information
{
    long num; //学号//
    char name[6];//姓名//
    struct information *next;/*指向下一个结构体*/
};

int main()
{
    char ch;
    struct information *fun();//建立链表函数的声明
    void shuchu(struct information *);//输出链表函数声明
    struct information *head;
    head=fun();                   //信息提示说这里的=错了,我不太懂额     f:\程序代码\list3.c(15) : error C2115: '=' : incompatible types
    //输入一个y时调用输出链表的函数
    ch=getchar();
    if(ch=='y')
        shuchu(head);
    return 0;
   
}
//尾插法建立带有头指针的链表
struct information *fun()//
{
    struct information *last=NULL;//尾指针
    struct information *he;//头指针
    struct information *p,*p1;
   
    he=p=(struct information *)malloc(sizeof(struct information));//申请空间//
    he->next=NULL;
    last=he->next;
    scanf("%ld",&p->num);//输入学号,姓名//
    scanf("%s",p->name);
    //输入信息直到学号为零//
    while(p->num!=0)
    {  
        if(he->next==NULL)
            he->next=p;
        else
            last->next=p;
        last=p;
        p1=he;//将p1指向链表的表头
        p=(struct information *)malloc(sizeof(struct information));//申请空间//
        scanf("%ld",&p->num);
        if(p->num==0)
        {
            free(p);break;
        }
        scanf("%s",p->name);
        p->next=NULL;
    }
    return p1;//返回p1   这个地方提示说错了  f:\程序代码\list3.c(50) : error C2115: 'return' : incompatible types
}
//链表的遍历
void shuchu(struct information *head)
{
    while(head!=NULL)
    {
        printf("%ld,%s\n",head->num,head->name);
    head=head->next;
    }
}
改动处
2012-04-16 22:15
难的哟
Rank: 2
等 级:论坛游民
帖 子:26
专家分:34
注 册:2012-1-25
收藏
得分:0 
回复 2楼 sunqing
谢谢你啊
2012-04-16 22:56
难的哟
Rank: 2
等 级:论坛游民
帖 子:26
专家分:34
注 册:2012-1-25
收藏
得分:0 
回复 2楼 sunqing
  还有个小问题就是改动以后的代码可以编译连接了
不过在调试的时候发现它好像不执行主函数中的
        ch=getchar();
        if(ch=='y')
        shuchu(head);
这三句   就显示 press any keys to contio链表其它都输入正常
我运行的环境是vc6.0
2012-04-16 23:09
快速回复:各位朋友进来帮看看为什么错啊
数据加载中...
 
   



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

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