小哥,你让我怎么说你呢,你注释的部分,i都没有定义,这个先不说,你的形参L用的是值传递,这就是说明只是在调用函数中使用,返回不到主函数中,要想返回主函数中,你可以定义成指针函数,或者在形参里面用指针,还有就是你的init函数中输出里面有个sizeof有个字母打错了,恩,就这样,我帮你调试了一下,运行没有问题,发给你哈。
#include
#include
#define LIST_INIT_SIZE 10
typedef struct
{
int * elem;
int length;
int listsize;
}SqList;
void init_l(SqList *L){
L->elem = (int *)malloc(LIST_INIT_SIZE * sizeof(int));
L->length = 5;
L->listsize = LIST_INIT_SIZE;
printf("sizeof=%d\n", sizeof(L));
printf("L.length=%d\n", L->length);
}
void list_length(SqList L){
printf("L.length=%d\n", L.length);
}
void insert_l(SqList *L, int e){
/*if( i<0 || i>L.length+1)
printf("i值不合法!\n");*/
L->elem[2] = e; //这样插入怎么不行????
printf("%d\n",L->elem[2]);
}
int main()
{
SqList L;
init_l(&L);
list_length(L);//输出的L不对啊
insert_l(&L, 3);
system("pause");
return 0;
}