Segmentation fault(coredump)
#include <stdio.h>
struct Node
{
int data;
struct Node *next;
};
typedef struct Node node ;
typedef node *list;
int main(int argc, char *argv[])
{
int n;
list head = NULL;
list temp = (list)malloc(sizeof(node));
head = temp;
printf( "please input node: ");
scanf( "%d ", &n);
if (temp != NULL)
{
temp-> data = n; //问题出在这里
}
else
{
printf( "create failure!\n ");
exit(1);
}
printf( "The list has create!\n ");
return 0;
}
执行结果:
please input node:5
Segmentation fault(coredump)
这是什么问题?
[解决办法]
你申请的段产生问题了,在程序最后加入free(temp);
看看!
[解决办法]
看不出有什么问题啊,这个core dump有些蹊跷
[解决办法]
看不出什么问题呀.
可能是你没包含stdlib.h这个文件.