I want to initial the sequence list by using a second rank pointer,which point to the STRUCT I made for the sequence list. I tried , the script can be compiled to an executable file ,but fail to operate.
I am using C with the DEV CPP 5.11 as the IDE.
I just want to use the *Sqlist as my parameter to initialize a sequence list...
here is the sequence list .
/* can be compiled ,but fail to execute.*/
#include <stdio.h>
#include <stdlib.h>
#define LISTSIZE 10
typedef int ElemType;
typedef struct List{
ElemType *elem;
int length;
int listsize;
}List,*Sqlist;
int InitList(Sqlist *L){
(*L)->elem=(ElemType*)malloc(sizeof(ElemType)*LISTSIZE);
if (!(*L)->elem) return -1;
(*L)->length=0;
(*L)->listsize=LISTSIZE;
}
int main(){
Sqlist La;
InitList(&La);
}
And this is comfusing compared with the linklist I made with a second rank pointer as the paramenter of the Initialize function.
#include <stdlib.h>
#include <stdio.h>
#include <typeinfo.h>
typedef int ElemType ;
typedef struct LNode{
ElemType data;
struct LNode* next;
}LNode,*LinkList;
int InitList(LinkList *L) {
(*L)=(LinkList)malloc(sizeof(struct LNode));
if (!*L) return -1;
(*L)->data= 0;
(*L)->next =NULL;
printf("successfully initialized.\n");
return 0;
}
I really appreciate your help!