问题补充:
我有以下一个c语言程序:
#include #include "ctest.h"typedef struct person{ unsigned int node; int age;}prs;void main(){ sli* list = NULL; prs p1,p2,p3,p4,p5; prs *tmp; int ret1,ret2,ret3,ret4,ret5,i; p1.age=23; p2.age=25; p3.age=22; p4.age=21; p5.age=27; list=slcreat(); ret1 = slinsert(list,(unsigned int)(&p1),0); ret2 = slinsert(list,(unsigned int)(&p2),0); ret3 = slinsert(list,(unsigned int)(&p3),0); ret4 = slinsert(list,(unsigned int)(&p4),0); //ret5 = slinsert(list,(unsigned int)(&p5),0); for(i=0;iage); } clear(list); printf("hello\n");}
以下是ctest.h程序内容:
typedef struct slist{ int size; unsigned int *node; }sli;sli* slcreat(){ sli *tmp=NULL; tmp=malloc(sizeof(sli)); tmp->node=(unsigned int *)malloc(sizeof(unsigned int *)); tmp->size=0; return tmp; }int slinsert(sli* insertsl,unsigned int* sn,int pos){ int i=0; if(insertsl->size!=0) { for(i=insertsl->size;i>pos;--i) { insertsl->node[i]=insertsl->node[i-1]; } } insertsl->node[i]=sn; ++insertsl->size; return insertsl->node[i];}unsigned int get(sli* sourcesl,int pos){ return sourcesl->node[pos];}int size(sli* sourcesl){ return sourcesl->size;}void clear(sli* sourcesl){ sourcesl->size=0;}int delete(sli* deletesl,int pos){ int i=0,ret=0; ret=deletesl->node[pos]; for(i=pos;isize-1;--i) { deletesl->node[i]=deletesl->node[i+1]; } --deletesl->size; return ret;}
以上的程序运行正常没问题,但是我把//ret5 = slinsert(list,(unsigned int)(&p5),0); 这行前面的//去掉后,运行时候程序中断,为什么?我只是在list中增多一个数据就运行中断了,程序出了什么错误,请各位高手指教?