数据结构 为什么一直说我L未初始化

#include 
#include 
#include 
#define OVERFLOW -2
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 10

typedef int Status;
typedef int ElemType;

typedef  struct {
ElemType *elem;
int length;
int listsize;
}SqList;

Status InitList_Sq(SqList *L);
Status ListInsert_Sq(SqList *L, int i, ElemType e);
void PrintList(SqList *L);

Status InitList_Sq(SqList L) {
L->elem = (ElemType
)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if (!L->elem)
exit(OVERFLOW);
L->length = 0;
L->listsize = LIST_INIT_SIZE;
return OK;
}

void PrintList(SqList *L) {
for (int i = 0; i < L->length - 1; i++) {
printf("%c", L->elem[i]);
}
}

int main() {
SqList sq;
SqList* L = &sq;
Status InitList_Sq(L);
L->length = 6;
L->elem[0] = 1;
L->elem[1] = 2;
L->elem[2] = 3;
L->elem[3] = 4;
L->elem[4] = 5;
L->elem[5] = 6;
void PrintList(L); 
return OK;
}

代码给你稍微修改了下

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define OVERFLOW -2
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 10

typedef int Status;
typedef int ElemType;

typedef  struct {
    ElemType* elem;
    int length;
    int listsize;
}SqList;

Status InitList_Sq(SqList* L);
Status ListInsert_Sq(SqList* L, int i, ElemType e);
void PrintList(SqList* L);

Status InitList_Sq(SqList* L) {
    L->elem = (ElemType*)malloc(LIST_INIT_SIZE * sizeof(ElemType));
    if (!L->elem)
        exit(OVERFLOW);
    L->length = 0;
    L->listsize = LIST_INIT_SIZE;
    return OK;
}

void PrintList(SqList* L) {
    for (int i = 0; i < L->length - 1; i++) {
        printf("%c", L->elem[i]);
    }
}

int main() {
    SqList sq;
    SqList* L = &sq;
    InitList_Sq(L);
    L->length = 6;
    L->elem[0] = 1;
    L->elem[1] = 2;
    L->elem[2] = 3;
    L->elem[3] = 4;
    L->elem[4] = 5;
    L->elem[5] = 6;
    PrintList(L);
    return OK;
}

如有帮助,采纳一下呗

帮你修改好了

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>

#define OVERFLOW -2
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 10

typedef int Status;
typedef int ElemType;

typedef struct {
  ElemType *elem;
  int length;
  int listsize;
} SqList;

Status InitList_Sq(SqList *L);
void DeleteList_Sq(SqList *L);
Status ListInsert_Sq(SqList *L, int i, ElemType e);
void PrintList(SqList *L);

Status InitList_Sq(SqList *L) {
  L->elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
  if (!L->elem)
    exit(OVERFLOW);
  L->length = 0;
  L->listsize = LIST_INIT_SIZE;
  return OK;
}

void DeleteList_Sq(SqList *L) {
  free(L->elem);
  L->elem = NULL;
  L->length = 0;
  L->listsize = 0;
}

void PrintList(SqList *L) {
  for (int i = 0; i < L->length; i++)
    printf("%d ", L->elem[i]);
  printf("\n");
}

int main() {
  SqList sq;
  SqList *L = &sq;
  InitList_Sq(L);
  L->length = 6;
  L->elem[0] = 1;
  L->elem[1] = 2;
  L->elem[2] = 3;
  L->elem[3] = 4;
  L->elem[4] = 5;
  L->elem[5] = 6;
  PrintList(L);
  DeleteList_Sq(L);
  return OK;
}