I was trying to create a dinamic queue, but I'm having some problem taking the idea of how C handles the pointers, I can't even compile this code it says :
queue.c: In function `enqueue':
queue.c:75: error: dereferencing pointer to incomplete type
queue.c:76: error: dereferencing pointer to incomplete type
queue.c:81: error: dereferencing pointer to incomplete type
queue.c: In function `dequeue':
queue.c:93: error: dereferencing pointer to incomplete type
queue.c:95: error: dereferencing pointer to incomplete type
queue.c: In function `printQueue':
queue.c:112: error: dereferencing pointer to incomplete type
queue.c:113: error: dereferencing pointer to incomplete type
Code:
#include<stdio.h>
#include<stdlib.h>
struct queueNode {
char data;
struct queueNode *nextPtr;
};
typedef struct queueNode QUEUENODE;
typedef struct QUEUENODE *QUEUENODEPTR;
/*Functions Prototipes*/
void printQueue(QUEUENODEPTR);
int isEmpty(QUEUENODEPTR);
char dequeue(QUEUENODEPTR *, QUEUENODEPTR *);
void enqueue(QUEUENODEPTR *, QUEUENODEPTR *, char);
void instructions(void);
int main(){
QUEUENODEPTR headPtr = NULL, tailPtr = NULL;
int choice;
char item;
instructions();
printf("?");
scanf("%d", &choice);
while (choice != 3){
switch (choice){
case 1:
printf("Give me a char: ");
scanf("\n%c", &item);
enqueue(&headPtr, &tailPtr, item);
printQueue(headPtr);
break;
case 2:
if (!isEmpty(headPtr)){
item = dequeue(&headPtr, &tailPtr);
printf("%c was successufully remove: ", item);
}
printQueue(headPtr);
break;
default:
printf("Invalid Choice\n\n");
instructions();
break;
}
printf("?");
scanf("%d",choice);
}
printf("Exit\n");
return 0;
}
void instructions( void ){
printf("Make a choice:\n"
"1 to add an item.\n"
"2 to remove an item.\n"
"3 to exit\n");
}
void enqueue(QUEUENODEPTR *headPtr, QUEUENODEPTR *tailPtr, char value)
{
QUEUENODEPTR newPtr;
newPtr = malloc(sizeof(QUEUENODE));
if (newPtr != NULL){
newPtr->data = value;
newPtr->nextPtr = NULL;
if (isEmpty(*headPtr))
*headPtr = newPtr;
else
(*tailPtr)->nextPtr = newPtr;
*tailPtr = newPtr;
}
else
printf("%c was not inserted. There is no enought memory\n", value);
}
char dequeue(QUEUENODEPTR *headPtr, QUEUENODEPTR *tailPtr){
char value;
QUEUENODEPTR tempPtr;
value = (*headPtr)->data;
tempPtr = *headPtr;
*headPtr = (*headPtr)->nextPtr;
if (*headPtr == NULL)
*tailPtr = NULL;
free(tempPtr);
return value;
}
int isEmpty(QUEUENODEPTR headPtr){
return headPtr == NULL;
}
void printQueue(QUEUENODEPTR currentPtr){
if (currentPtr == NULL)
printf("The Queue is Empty");
else {
printf("The queue is: \n");
while(currentPtr != NULL){
printf("%c --> ",currentPtr->data);
currentPtr = currentPtr->nextPtr;
}
printf("NULL\n\n");
}
}
So should I try to make a cast os something like this?