如图出现了这样的编译错误,在这个代码中出现了什么错误要怎么修改
5条回答 默认 最新
关注 引自免费微信小程序:皆我百晓生
在您提供的代码中,存在一些语法错误和逻辑上的小问题。以下是修正后的代码:
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> // 定义结构体类型 typedef struct Lnode { int data; struct Lnode *next; } Lnode, *Linklist; // 初始化链表函数 bool Initlist(Linklist *L) { *L = (Linklist)malloc(sizeof(Lnode)); if (*L == NULL) { return false; } (*L)->next = NULL; // 注意这里使用了指针解引用操作符 * return true; } // 测试函数 void test() { Linklist L; Initlist(&L); } int main() { test(); return 0; }
主要的问题在于第6行的
struct Lnode next;
应该写成struct Lnode *next;
,因为你想要的是指向结构体的指针,而不是实际的结构体。然后在第9行,你需要使用指针解引用操作符(*)来访问Linklist
类型的变量L
中的成员next
。修正后的代码应该可以正确编译并运行。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 关于#.net#的问题:End Function
- ¥50 用AT89C52单片机设计一个温度测量与控制电路
- ¥15 无法import pycausal
- ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
- ¥15 weditor无法连接模拟器Local server not started, start with?
- ¥20 6-3 String类定义
- ¥15 嵌入式--定时器使用
- ¥20 51单片机学习中的问题
- ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
- ¥15 Python中knn问题