fyn123456fyn 2016-10-05 03:54 采纳率: 0%
浏览 1129

为什么c程序运行到最后结果已经出来了,但是还报错了

#include
#include
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
struct list
{
int elem;
int length;
int listsize;
};
void InitList(struct list *L)
{
L->elem = (int
)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L->elem)
exit(0);
L->length = 0;
L->listsize = LIST_INIT_SIZE;
}
void CreateList(struct list L,int n)
{
int *p;
int i;
if(n > LIST_INIT_SIZE)
{
free(L->elem);
L->elem = (int
)malloc((n+10)*sizeof(int));
if(!L->elem)
exit(0);
L->length = 0;
L->listsize = n+10;
}
p = L->elem;
for(i = 1;i <= n;i++)
{
scanf("%d",&(L->elem[i-1]));
L->length++;
}
L->elem = p;
}
int ListLength(struct list L)
{
return L->length;
}
int GetElem(struct list *L,int i,int *e)
{
if((i >= 1) && (i <= L->length))
{
e = &(L->elem[i -1]);
}
return *e;
}
int ListInsert(struct list *L,int i,int e)
{
int *p,*q,*newbase;
if(i < 1 || i > L->length+1)
{
return 0;
}
if(L->length >= L->listsize)
{
newbase = (int
)realloc(L->elem,(L->listsize+LISTINCREMENT)*sizeof(int));
if(!newbase)exit(0);
L->elem = newbase;
L->listsize = L->listsize + LISTINCREMENT;
}
q = &(L->elem[i-1]);
for(p = &(L->elem[L->length-1]);p >= q;--p)
{
*(p+1) = *p;
}
*q = e;
++L->length;
return 1;
}
void f4(struct list *La,struct list *Lb,struct list *Lc)
{
int La_length,Lb_length;
int i=1,j=1,k=0;
int *p,*q;
La_length = ListLength(La);
Lb_length = ListLength(Lb);
while((i <= La_length) && (j <= Lb_length))
{
*p=GetElem(La,i,p);
*q=GetElem(Lb,j,q);
if(*p <= *q)
{
ListInsert(Lc,++k,*p);
++i;
}else
{
ListInsert(Lc,++k,*q);
++j;

}
}
while(i <= La_length)
{
*p=GetElem(La,i++,p);
ListInsert(Lc,++k,*p);
}
while(j <= Lb_length)
{
*q=GetElem(Lb,j++,q);
ListInsert(Lc,++k,*q);
}
printf("\n");
}
int main()
{
int i;
struct list La;
struct list Lb;
struct list Lc;
//int *p;
InitList(&La);
CreateList(&La,3);
InitList(&Lb);
CreateList(&Lb,3);
InitList(&Lc);
f4(&La,&Lb,&Lc);!
for(i = 0;i < 6;i++)
{
printf("%d ",Lc.elem[i]);
}
图片说明

  • 写回答

6条回答 默认 最新

  • T_world 2016-10-05 03:56
    关注

    这种情况一般是非法访问内存等行为导致了程序崩溃

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c