才开始学,遇到如下问题,请指教一下:
这里为什么初始化时,不先定义一个SqList *p;运行就出错呢?
void InitList(SqList *L) // 这个能通过.
{
SqList *p;
p = (SqList *)malloc(List_Maxsize * sizeof(SqList));
if(!p) exit (OVERFLOW);
p=L;
L->length=0;
printf("InitList is OK!\n\t The L.length = %d",L->length);
}
int Input_SqL(SqList *L)
{
int i=0;
InitList(L);
printf("\nPlease Input:\n");
while((scanf("%d",&L->data[i++]))==1&&i<ListMax) ++L->length;
printf("\n\n\tInput_SqL: L->length = %d\n",L->length);
}
/*
void InitList(SqList *L) // 这个为什么不行?
{
L = (SqList *)malloc(List_Maxsize * sizeof(SqList));
if(!L) exit (OVERFLOW);
L->length=0;
printf("InitList is OK!\n\t The L.length = %d",L->length);
}
*/