Can somebody please tell me what im doing wrong, I know its the initVirtualHeap but i dont know why. The program just crashes.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 10
typedef struct{
char elem;
int next;
}vArray;
typedef struct{
vArray *nodes;
int avail;
}virtualHeap;
typedef int List;
void initList(virtualHeap *);
int initVirtualHeap(virtualHeap *);
void insertValues(virtualHeap *, List*);
void insertSortedUnique(virtualHeap *, List, char);
int main()
{
virtualHeap *A;
List B;
initList(A);
B=initVirtualHeap(A);
insertValues(A, &B);
getch();
return 0;
}
void initList(virtualHeap *V)
{
V=(virtualHeap *)malloc(sizeof(virtualHeap));
V->nodes=(vArray *)malloc(sizeof(vArray)*MAX);
V->avail=-1;
}
int initVirtualHeap(virtualHeap *V)
{
int p;
for (p=0;p<MAX;p++){
V->nodes[p].next=p-1;
}
V->avail=MAX-1;
p=V->avail;
return p;
}
void insertValues(virtualHeap *V, List *A)
{
int p, temp;
for (p=*A;p!=-1;p=V->nodes[p].next){
temp=V->avail;
if(temp!=-1){
V->avail=V->nodes[temp].next;
}
printf("Enter character: ");
scanf("%c", &V->nodes[p].elem);
}
}