求高手指点,初始化顺序表,内存有问题?

小黑煤 2017-02-26 07:41:55
用Dev-C++写了一个初始化顺序表的函数,编译通过了,不知道为什么老是终止运行,会弹出SIGSEGV。
初学者看了几天了还处于懵逼状态,快要失去信心了TAT
#include<stdio.h>
#include<stdlib.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10

typedef struct{
int *elem;
int length;
int listsize;
}SqList;

typedef enum{Overflow=-1,wrong,ok}status;
status initlist(SqList* &L){
L->listsize=LIST_INIT_SIZE;
assert(L->listsize==LIST_INIT_SIZE);
L->elem=(int*)malloc((L->listsize)*sizeof(int));

if(L->elem==NULL)
exit(Overflow);
L->length=0;
return ok;
}

int main(){
int i;
SqList *p;
SqList a;
p=&a;
initlist(p);
printf("创建线性表后\n线性表的长度:%d",p->length);
printf("\n线性表的总长度:%d",p->listsize);
return 0;

}
...全文
166 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
小灸舞 版主 2017-02-27
  • 打赏
  • 举报
回复
官方说法是:
SIGSEGV --- Segment Fault. The possible cases of your encountering this error are:

1.buffer overflow --- usually caused by a pointer reference out of range.

2.stack overflow --- please keep in mind that the default stack size is 8192K.

3.illegal file access --- file operations are forbidden on our judge system.
小黑煤 2017-02-26
  • 打赏
  • 举报
回复
我的devc++编译器配置出错了,现在改好了,可以运行。在vs中把引用去掉也可以运行了。谢谢各位指点。
小黑煤 2017-02-26
  • 打赏
  • 举报
回复
引用 3 楼 xsklld的回复:
status initlist(SqList* &L) // 这里的引用毫无意义,反而会使得诸如 initlist(&a) 这样的表达式无法通过编译
嗯嗯,以后会注意的,谢谢大神指出来
xskxzr 2017-02-26
  • 打赏
  • 举报
回复
status initlist(SqList* &L) // 这里的引用毫无意义,反而会使得诸如 initlist(&a) 这样的表达式无法通过编译
小黑煤 2017-02-26
  • 打赏
  • 举报
回复
引用 1 楼 zycxnanwang的回复:
程序我检查了一下 应该没错,这是我运行处的结果
难道是我用的编译器有问题?
zycxnanwang 2017-02-26
  • 打赏
  • 举报
回复
程序我检查了一下 应该没错,这是我运行处的结果

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧