Hey I'm trying to move pointer memory allocation d =(deque*)malloc(sizeof(deque));
into first function called void initDeque()
. I tried leaving declaration in main
and allocating memory in the function, but program just crashes after initializing the deque and I can't use the pointer in other functions.
Here's the code:
int main(){
int x;
deque *d;
d = (deque*)malloc(sizeof(deque));
initDeque(d);
putFront(d,10);
And the function where I want to move memory allocation for pointer:
void initDeque(deque *d){ //Create new deque
//d = (deque*)malloc(sizeof(deque));
printf("Initializing deque\n");
d->front=NULL;
d->rear=NULL;
}
Program runs great if declaration and allocation is in the main()
, but it crashes when I put allocation into void initDeque
.