我在ubuntu上使用ECLIPSE IDE 我编写了简单的代码来创建树头。 代码正在成功编译。但是在调试时,只要它执行malloc语句就会出错。
错误
在“/build/buildd/glibc-2.19/malloc/malloc.c”找不到源文件 找到文件或编辑源查找路径以包含其位置。
/*
* tree.c
*
* Created on: 04-Dec-2014
* Author: etron
*/
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node
{
int key_value;
struct node *right;
struct node *left;
};
struct node *root=0;
struct node* insert(int key,struct node **leaf)
{
if(*leaf == 0)
{
*leaf = (struct node*) malloc(sizeof(struct node));
(*leaf)->key_value = key;
(*leaf)->left = 0;
(*leaf)->right = 0;
return 0;
}
}
void main()
{
struct node *bt=0;
int i=100;
insert(i,&bt);
}
答案 0 :(得分:1)
从调试到malloc几乎没有什么好处。只是不要试图进入malloc。你的主要是错的。 int main(void)
。并且不要强制转换malloc的返回值。启用并注意编译器警告。它会抱怨你没有从插入返回。 malloc
声明了stdlib.h
。为什么要包含malloc.h
?
- 大卫赫弗南
谢谢Sir先生,它与step Over Run合作 - user1551103