| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 584 人关注过本帖
标题:求解!!!链表,究竟是哪里出错
只看楼主 加入收藏
hd小狼崽
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-12-7
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:8 
求解!!!链表,究竟是哪里出错
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
    long num;
    float score;
    struct student *next;
};
int n;

struct student *creat(void)
{
    struct student *head;
    struct student *p1,*p2;
    n=0;
    p1=p2=(struct student *)malloc(LEN);
    scanf("%ld,%f",&p1->num,&p1->score);
    head=NULL;
    while(p1->num!=0)
    {
        n=n+1;
        if(n==1)head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct student *)malloc(LEN);
        scanf("%ld,%f",p1->num,p1->score);
    }
    p2->next=NULL;
    return(head);
}

出现的错误提示:--------------------Configuration: 6.c - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/6.c.exe : fatal error LNK1120: 1 unresolved externals
搜索更多相关主题的帖子: head next include 
2012-12-07 16:15
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:5 
没有main函数

写个main函数就行了

void main()
{
 // ……
}

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2012-12-07 18:26
wu_jian_long
Rank: 2
等 级:论坛游民
帖 子:4
专家分:15
注 册:2012-12-7
收藏
得分:15 
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)

struct student *creat(void);
void TraverseLink(struct student * );

struct student
{
    long num;
    float score;
    struct student *next;
};



int main(void)
{
   struct student * Link;
    Link = creat();
    TraverseLink(Link);

    return 0;
}



struct student *creat(void)
{

    int n;
    struct student *head;
    struct student *p1,*p2;
    n=0;
    p1=p2=(struct student *)malloc(LEN);
    printf("请输入num和score的值,中间用逗号隔开,当输入num中为0时结束\n");
    scanf("%ld,%f",&p1->num,&p1->score);
    head=NULL;
    while(p1->num!=0)
    {
        n=n+1;
        if(n==1)head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct student *)malloc(LEN);
        printf("请输入num和score的值,中间用逗号隔开,当输入num中为0时结束\n");
        scanf("%ld,%f",p1->num,p1->score);
    }
    p2->next=NULL;
    return(head);
}

void TraverseLink(struct student * pLink)
{
      struct student * pN=pLink;
      while( NULL != pN->next)
      {
           printf("%ld,%f\n",pN->num,pN->score);
            pN = pN->next;
  
      }   

}
2012-12-07 23:18
wu_jian_long
Rank: 2
等 级:论坛游民
帖 子:4
专家分:15
注 册:2012-12-7
收藏
得分:0 
这个程序暂时有点问题。明天在调试一下。今天有点晚了。明天还要工作。
2012-12-07 23:20
hd小狼崽
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-12-7
收藏
得分:0 
回复 2楼 yuccn
大神啊!!!!一眼就看出问题所在。佩服。。。
2012-12-08 13:48
hd小狼崽
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-12-7
收藏
得分:0 
回复 3楼 wu_jian_long
不错不错,你写的代码让我发现我的代码的不少问题
2012-12-08 13:50
hd小狼崽
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-12-7
收藏
得分:0 
第一次感觉到论坛的收益匪浅啊,,,,决定以后要多逛论坛了!!!!!
2012-12-08 13:52
小强。小强
Rank: 2
来 自:山西大同
等 级:论坛游民
帖 子:42
专家分:56
注 册:2012-11-15
收藏
得分:0 
程序代码:
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
    long num;
    float score;
    struct student *next;
};


 
      int n;
    struct student *creat(void)
    {
        struct student *head;
        struct student *p1,*p2;
        n=0;
        p1=p2=(struct student *)malloc(LEN);
        scanf("%ld,%f",&p1->num,&p1->score);
        head=NULL;
        while(p1->num!=0)
        {
            n=n+1;
            if(n==1)
             head=p1;
            else
                p2->next=p1;
            p2=p1;
            p1=(struct student *)malloc(LEN);
            scanf("%ld,%f",p1->num,p1->score);
        }
        p2->next=NULL;
        return(head);
    }


 int main()

 {
     printf("please enter num,score;\n");
      struct student * p;
      p=creat();
      printf("num is%d, score is %f\n",p->num ,p->score );
      return 0;

 }
除主函数外主函数,还有要告诉人家输入啥东东(也可以不写)
  错了见谅啊!
2012-12-08 15:52
wu_jian_long
Rank: 2
等 级:论坛游民
帖 子:4
专家分:15
注 册:2012-12-7
收藏
得分:0 
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)

struct student *creat(void);
void TraverseLink(struct student * );

struct student
{
    long num;
    float score;
    struct student *next;
};



int main(void)
{
   struct student * Link;
    Link = creat();
    TraverseLink(Link);

    return 0;
}



struct student *creat(void)
{

    int n=0;
    struct student *head;
    struct student *p1,*p2;
     head=NULL;
    p1=(struct student *)malloc(LEN);
    printf("请输入num和score的值,中间用逗号隔开,当输入num中为0时结束\n");
    scanf("%ld,%f",&p1->num,&p1->score);
    while(p1->num)
    {
        n++;
        if(n==1)  head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct student *)malloc(LEN);
        printf("请输入num和score的值,中间用逗号隔开,当输入num中为0时结束\n");
        scanf("%ld,%f",&p1->num,&p1->score);
    }
    p2->next=NULL;
    return(head);
}

void TraverseLink(struct student * pLink)
{
      struct student * pN=pLink;
      while( NULL != pN->next)
      {
           printf("%ld,%f\n",pN->num,pN->score);
           pN = pN->next;
      }   

}
test.rar (570.58 KB)



使用的编译器是vc2010

[ 本帖最后由 wu_jian_long 于 2012-12-8 21:23 编辑 ]
2012-12-08 21:20
快速回复:求解!!!链表,究竟是哪里出错
数据加载中...
 
   



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

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