function call in data structure
I want to delete the i-th element in the sequence table, and delete it by calling my own defined DelList function in the main function, but after compiling, I can't print out the value of the deleted element as expected. The code before line 48 works fine, but it seems that the DelList function cannot be called, resulting in no deleted elements being printed. Is there a problem with calling the DelList function? Or is there a problem with the return of the DelList function? Thank you
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
#define OK 1
#define ERROR 0
typedef int ElemType; /*Assume that the data elements in the sequence table
are integers*/
typedef struct {
ElemType elem[MAXSIZE];
int last;
}SeqList;
int DelList(SeqList *L, int i, ElemType *e)
/*The i-th data element is deleted in the sequence table L, and its value is returned with the pointer parameter e. The legal value of i is 1 ≤ i ≤ L. last +1 */
{
int k;
if ((i < 1) || (i > L->last + 1))
{
printf("Deleting the location is not legal!");
return(ERROR);
}
*e = L->elem[i - 1]; /* Store the deleted element in the variable pointed to by e*/
for (k = i; i <= L->last; k++)
L->elem[k - 1] = L->elem[k]; /*Move the following elements forward*/
L->last--;
return(OK);
}
void main()
{
SeqList *l;
int p, r;
int *q;
int i;
l = (SeqList*)malloc(sizeof(SeqList));
q = (int*)malloc(sizeof(int));
printf("Please enter the length :");
scanf("%d", &r);
l->last = r - 1;
printf("Please enter the value of each element:\n");
for (i = 0; i <= l->last; i++)
{
scanf("%d", &l->elem[i]);
}
printf("Please enter the location of the element you want to delete:\n");
scanf("%d", &p);
DelList(l, p, q);
printf("The deleted element value is:%d\n", *q);
}
Compile can pass but not the result I want