【发布时间】:2013-10-05 20:26:23
【问题描述】:
我想创建一个链表,从其他地方的主目录调用。这个链表是由节点组成的。
例如,这不是我的代码,只是它的简化版本。
nodeTest.h
#include <stdio.h>
#include <stdlib.h>
struct nodeTest
{
int data;
struct nodeTest* next;
};
然后我有另一个文件试图使用该结构:
nodeTest.c
#include <stdio.h>
#include <stdlib.h>
#include "nodeTest.h"
int main(void) {
struct nodeTest* first = malloc(sizeof(struct nodeTest));
first->data = 0;
return 0;
}
void addLL(int data){
if (first.data = 0)
{
printf("No head\n");
}
}
我想首先成为链表中的第一个元素,那么如何为它定义一个首先使用的 addElement?现在,当我第一次打电话时,我遇到了一个无法识别的错误。
这是我在主链表文件中得到错误的地方
void addLL(int data){
if (head.data = 0)
我在 if 行收到错误,头部无法识别。
【问题讨论】:
-
1.您不需要在 C 程序中强制转换
malloc的返回值。 2.请显示实际代码;您的第一个malloc调用甚至不在函数中。 -
为什么不需要退货?这基本上是实际代码。需要改变什么?你需要看什么?
-
编译的代码示例;还有错误是什么样的?
-
@PaulGriffiths 我不这么认为,我想知道更多关于这段代码如何与主文件一起工作以及专门调用其他函数的细节。