标题:链表的最简单的问题
取消只看楼主
wly2014
Rank: 2
等 级:论坛游民
帖 子:29
专家分:19
注 册:2014-2-25
结帖率:88.89%
已结贴  问题点数:20 回复次数:1 
链表的最简单的问题
初学c语言链表,就不幸的卡在了这里
注释处为错误;
#include<stdio.h>
#include<stdlib.h>
#include<alloc.h>            // Cannot open include file: 'alloc.h': No such file or directory
struct node{
    int data;
    struct node *next;
}

int main()
{
    struct node *head,*p1,*p2;
    head =(struct node *)malloc(sizeof(struct node));
    p1 =(struct node *)malloc(sizeof(struct node));
    p2 =(struct node *)malloc(sizeof(struct node));
    head->data=1000;head->next=p1;
    p1->data=1001;p1->next=p2;
    p2->data=1002;p2->next=NULL;
    while (head!=NULL){
        printf("%d\n",head->data);
        p1=head;
        head=head->next;
        free(p1);
    }
    return 0;
}
搜索更多相关主题的帖子: include c语言 file 
2014-05-09 19:43
wly2014
Rank: 2
等 级:论坛游民
帖 子:29
专家分:19
注 册:2014-2-25
得分:0 
太感谢了
2014-05-09 20:44



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




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

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