首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

Segmentation fault(coredump)解决方法

2012-03-26 
Segmentation fault(coredump)#includestdio.hstructNode{intdatastructNode*next}typedefstructNode

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这个文件.

热点排行