Question

I have the code in main.c:

#include <stdio.h>
#include "queue.h"

int main() {
    Queue Q = CreateQueue();
    /* other code */
    return 0;
}

And the Queue is defined in queue.h as:

#ifndef _queue_h

typedef struct QueueRecord * Queue;
struct QueueRecord {
    int Front, Rear;
    int * Array;
};

/* other function declarations */
Queue CreateQueque(); // <--- The Typo.

#endif

And function CreateQueue() is in file queue.c:

#include <stdio.h>
#include <stdlib.h>
#include "queue.h"

// CREATE THE QUEUE
Queue CreateQueue() {
    Queue Q = malloc(sizeof(struct QueueRecord));
    Q->Array = malloc(sizeof(int*) * MAX_SIZE);
    InitQueue(Q);
    return Q; /* Above goes right except cannot return the pointer. */
}

// INIT THE QUEUE
void InitQueue(Queue Q) {
    Q->Front = -1;
    Q->Rear = -1;
} /* this function does not make an error I think */

How could this be fixed? More Error Message was aborted:

double free or corruption (out): 0x00619270 

Thanks.

Was it helpful?

Solution

You have a typo in your declaration: you've declared "CreateQueque" rather than "CreateQueue". C defaults to an int return type for CreateQueue which is probably what's causing your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top