| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 644 人关注过本帖
标题:关于链表错误
只看楼主 加入收藏
gold615
Rank: 2
等 级:论坛游民
帖 子:54
专家分:75
注 册:2014-6-7
结帖率:55.56%
收藏
已结贴  问题点数:20 回复次数:1 
关于链表错误
创建一个简单的链表后,编译也能通过,但输出链表时总是有错误为什么?
#include<stdio.h>
#include<stdlib.h>
struct list
{
    int data;
    struct list *next;
} *Link;
void Creat_List(list *Link);
void Print_list(list *Link);
main()
{
    Creat_List(Link);
    printf("the list has been created\n");
    getchar();
    Print_list(Link);
}
void Creat_List(list *Link)
{
   
    printf("to creat the list\n");
    char c='y';
    int t;
    list *p,*q;
    Link=q=(list *)malloc(sizeof(list));
    while(c=='y')
    {
        
        printf("input the data:\t");
        scanf("%d",&t);
        p=(list *)malloc(sizeof(list));
        p->data=t;
        q->next=p;
        q=p;
        q->next=NULL;
        printf("press 'y' to continue or 'n' to exit\n");
        getchar();
        c=getchar();
    }
}

void Print_list(list *Link)
{
    list *p;
    p=Link->next;
    while(p)
    {
        printf("%d\t",p->data);
        p=p->next;
    }
    printf("\n");
}
搜索更多相关主题的帖子: created include 
2015-06-18 14:33
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:20 
程序代码:
#include<stdio.h>
#include<stdlib.h>
struct list
{
    int data;
    struct list *next;
} *Link;
struct list* Creat_List(list *Link);
void Print_list(list *Link);
main(){
    Link=Creat_List(Link);
    printf("the list has been created\n");
    getchar();
    Print_list(Link);
}
struct list* Creat_List(list *Link)
{
    
    printf("to creat the list\n");
    char c='y';
    int t;
    list *p,*q;
    Link=q=(list *)malloc(sizeof(list));
    while(c=='y')
    {
        
        printf("input the data:\t");
        scanf("%d",&t);
        p=(list *)malloc(sizeof(list));
        p->data=t;
        q->next=p;
        q=p;
        q->next=NULL;
        printf("press 'y' to continue or 'n' to exit\n");
        getchar();
        c=getchar();
    }
    return Link; 
}

void Print_list(list *Link)
{
    list *p;
    p=Link->next;
    while(p)
    {
        printf("%d\t",p->data);
        p=p->next;
    }
    printf("\n");
}

剑栈风樯各苦辛,别时冰雪到时春
2015-06-21 10:19
快速回复:关于链表错误
数据加载中...
 
   



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

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