Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C中创建列表时程序崩溃_C - Fatal编程技术网

在C中创建列表时程序崩溃

在C中创建列表时程序崩溃,c,C,我正在创建一个简单的单链接列表。在函数listIn()。我不明白为什么? 它给出如下输出: 进程在3.055秒后退出,返回值为322225477 按任意键继续 代码: main.c structure.h //自定义头文件结构.h(开始) //所有结构的定义 #包含//用于布尔数据类型。 #ifndef结构_ #定义结构_ #包括 类型定义结构节点 { int-lcode; 结构lnode*llink; }名单; 列表*tmplist; #恩迪夫 //自定义头文件结构.h(结束) 问题就在这里

我正在创建一个简单的单链接列表。在函数
listIn()。我不明白为什么?
它给出如下输出:


进程在3.055秒后退出,返回值为322225477 按任意键继续

代码:

main.c
structure.h
//自定义头文件结构.h(开始)
//所有结构的定义
#包含//用于布尔数据类型。
#ifndef结构_
#定义结构_
#包括
类型定义结构节点
{
int-lcode;
结构lnode*llink;
}名单;
列表*tmplist;
#恩迪夫
//自定义头文件结构.h(结束)
问题就在这里

if (tmplist = NULL)
这会在分配后立即将tmplist设置为NULL。这会使
if
测试失败,因此不会输入块。
if
后面的下一行立即崩溃

应该读

if (tmplist == NULL)

你应该得到有关这方面的警告。始终在启用警告的情况下编译。

第一个问题:
如果(tmplist=NULL)
-->
如果(tmplist==NULL)
请在启用警告的情况下重新编译代码并修复这些问题。接下来,请向我们展示List.h文件中的内容-我们不知道“List”是什么。已启用的警告捕获上述“=”vs“==”issue@MichaelDorgan它位于列表的底部。变量
lStart
lStart
是否相同?第二个在哪里申报?@bruceg谢谢你的提示。我将来会记住这一点。
//custom header file structure.h(begin)
// definition of all the structures
#include<stdbool.h>//for boolean data type.
#ifndef STRUCTURE_H_
#define STRUCTURE_H_
#include<stdbool.h>

typedef struct lnode
{
    int lcode;
    struct lnode *llink; 
}List;
List *tmplist;
#endif

// custom header file structure.h(end)
if (tmplist = NULL)
if (tmplist == NULL)