| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 314 人关注过本帖
标题:求助:求一个创建单向链表简单代码,对于链表创建一头雾水 里的代码执行不了 ...
取消只看楼主 加入收藏
zhaochunlong
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-10-25
收藏
 问题点数:0 回复次数:1 
求助:求一个创建单向链表简单代码,对于链表创建一头雾水 里的代码执行不了
在论坛上看见这个帖子 ,执行了这个代码 但是输入不了第二组成绩信息
一下是代码:
#include<Windows.h>
#include<stdio.h>
#include<malloc.h>
//#include<string.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);//开辟一个新单元
    printf("请输入第%d组学号和成绩:\n",n+1);
    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("请输入第%d组学号和成绩:\n",n+1);
    scanf("%ld,%f",&p1->num,&p1->score);
}
    p2->next=NULL;
    return (head);
}
void main()
{
    creat();
        system("pause");
}
搜索更多相关主题的帖子: include long next 
2012-10-25 17:46
zhaochunlong
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-10-25
收藏
得分:0 
怎么没回复。。。
2012-10-25 17:54
快速回复:求助:求一个创建单向链表简单代码,对于链表创建一头雾水 里的代码执 ...
数据加载中...
 
   



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

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