| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1766 人关注过本帖
标题:c的链表问题请教高手
取消只看楼主 加入收藏
无悔
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-4-15
收藏
 问题点数:0 回复次数:1 
c的链表问题请教高手
#include "stdio.h"
#include "malloc.h"
#define NULL 0
#define LEN sizeof(struct student)

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

int n;

struct student *creat(void)
{   struct student *head,*p1,*p2;
    n=0;
    p1=p2=(struct student *)malloc(LEN);
    printf("input p1.num,p1.score");
    scanf("%d,%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("%d,%f",&p1->num,&p1->score);
    }
    p2->next=NULL;
    return(head);
}
    


    
    
    
    
    
main()
{
    creat();
   
   
}    
在输入数字后就不对了,好像是格式不对,看不太懂,请高手给看看。
搜索更多相关主题的帖子: 链表 student struct num 
2008-04-20 14:43
无悔
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-4-15
收藏
得分:0 
怎么还没高手解释啊,是老谭的书,只介绍了怎么创建函数,没把函数运用到main中,所以不会,我的哪错了,我不要程序,只是想知道我的哪错了
2008-04-21 12:31
快速回复:c的链表问题请教高手
数据加载中...
 
   



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

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