| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 387 人关注过本帖
标题:求改错!!链表
只看楼主 加入收藏
方没
Rank: 2
等 级:论坛游民
帖 子:10
专家分:20
注 册:2011-12-4
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
求改错!!链表
   #include <stdio.h>
#include<malloc.h>
#define LEN sizeof(struct Student)
struct Student
{
    long num;
    float score;
    struct Student * next;
};
int n;


struct Student *head;
struct Student*creat(void)
{

    struct Student * p1,*p2;
    n=0;
    p1=p2=(struct Student*) malloc(LEN);
    scanf("%ld,%lf",&p1->num,&p1->score);
    head=NULL;
    while(p1->num!=0)
    {
        n=n+1;
        if(n==10)
            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);

}

void print (struct Student head)
{
    struct Student *p;
    printf("\nNow,There%d records are:\n",n);
    p=head;
    if(head!=NULL)
    do
    {
        printf("%ld%5.1f\n",p->num,p->score);
        p=p->next;
        
    }while(p!=NULL);
}
void main()   
{
    struct Student * pt;
    head=creat();
    print(head);
}
搜索更多相关主题的帖子: next long include 
2012-03-24 11:21
double聪
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:46
专家分:118
注 册:2011-11-19
收藏
得分:1 
先说说错在哪里嘛。。。
2012-03-25 19:38
瓦力
Rank: 2
等 级:论坛游民
帖 子:41
专家分:27
注 册:2011-11-18
收藏
得分:1 
想实现什么功能?
2012-03-25 22:03
瓦力
Rank: 2
等 级:论坛游民
帖 子:41
专家分:27
注 册:2011-11-18
收藏
得分:18 
程序代码:
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define LEN sizeof(struct Student)
struct Student
{
    long num;
    float score;
    struct Student * next;
};
int n;


struct Student *head;
struct Student *creat(void)
{

    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);

}

void print (struct Student *head)
{
    struct Student *p;
    printf("\nNow,There %d records are:\n",n);
    p=head;
    if(head == NULL){
        printf("Open fail!");
        exit(0);
    }
    do
    {
        printf("%ld \t %.2f\n",p->num, p->score);
        p=p->next;
        
    }while(p != NULL);
}
void main()    
{
   // struct Student * pt;
    head=creat();
    print(head);
}
2012-03-25 22:28
方没
Rank: 2
等 级:论坛游民
帖 子:10
专家分:20
注 册:2011-12-4
收藏
得分:0 
xiexie
2012-03-27 19:44
快速回复:求改错!!链表
数据加载中...
 
   



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

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