鱼C论坛

 找回密码
 立即注册
查看: 2337|回复: 4

[已解决]单链表,创建结点函数出错

[复制链接]
发表于 2018-1-6 14:39:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct list
{
        int data;
        struct list *next;
};

struct list *create_list ()
{
        return calloc (1,sizeof (struct list));//编译器这边报错,为什么?
}

void travese (struct list *ls)
{
        struct list *p = ls;
        while (p)
        {
                printf ("%d\n",p->data);
                p->next;
        }
}
int main ()
{
        struct list *first = create_list();
        struct list *second = create_list();
        struct list *third = create_list();
        first->data = 1;
        first->next = second;
        second->data = 2;
        second->next = third;
        third->data = 3;
        third->next = NULL;
        travese (first);
        return 0;
}
最佳答案
2018-1-6 16:18:13
fdsf 发表于 2018-1-6 15:41
13        46        C:%users\jiang\Desktop\新建文件夹\未命名1.cpp        [Error] invalid conversion from 'void*' to 'li ...

把 未命名1.cpp
改成 未命名1.c
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-1-6 14:54:39 | 显示全部楼层
我编译通过。你重起 电脑试试
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-1-6 15:41:41 | 显示全部楼层
ba21 发表于 2018-1-6 14:54
我编译通过。你重起 电脑试试

13        46        C:\Users\jiang\Desktop\新建文件夹\未命名1.cpp        [Error] invalid conversion from 'void*' to 'list*' [-fpermissive]    这是错误报告
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-1-6 16:18:13 | 显示全部楼层    本楼为最佳答案   
fdsf 发表于 2018-1-6 15:41
13        46        C:%users\jiang\Desktop\新建文件夹\未命名1.cpp        [Error] invalid conversion from 'void*' to 'li ...

把 未命名1.cpp
改成 未命名1.c
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-1-6 16:26:53 | 显示全部楼层
人造人 发表于 2018-1-6 16:18
把 未命名1.cpp
改成 未命名1.c

谢谢,现在可以了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-1 07:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表