标题:求助:求一个创建单向链表简单代码,对于链表创建一头雾水 里的代码执行不了 ...
取消只看楼主
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



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




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

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