我需要一些帮助来确定我的代码有什么问题:
我有一个结构
struct structName{
//members
} *pointerToStruct, *tail;
然后在main中我获得用户输入并调用函数来创建节点。
struct structName* createNewNode(int x){
struct Node* newNode = (struct Node*)calloc(3,sizeof(struct Node));
if (newNode == NULL){
perror("Calloc Failed... exiting\n");
exit (EXIT_FAILURE);
}
newNode->digit = x;
newNode->prev = NULL;
newNode->next = NULL;
return newNode;
}
然后另一个函数负责将事物连接在一起:
if(pointerToStruct == NULL) {
pointerToStruct = newNode; //where newNode is the node created in the above function
tail = newNode;
return;
}
pointerToStruct->prev = newNode;
newNode->next = pointerToStruct;
pointerToStruct = newNode;
Valgrind抱怨条件跳转或移动取决于未初始化的值。在memLocation:main(文件的位置)
我觉得很奇怪的是,在我创建节点之前,在我要求用户输入之前它是在main中报告此错误。它会立刻被标记出来。