I am trying to create a doubly linked list for a homework. I'm using the book mastering algorithms with C by Kyle Louden as a guideline. The book states that i need to initialize a doubly linked list before I use it which I'm trying to do but when I enter my code visual studios tells me "incomplete type not allowed for the following line "void dlist_init(Dlist *list, void (*destroy)(void *data)){}", it also states that Dlist is undefined but from what I understood that wasn't a variable to be defined. I am very new to this so i might be completely wrong. please let me know any problems you see. the full code is as follows :
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "bool.h"
#include "dlinklist.h"
#include "DlistElmt.h"
#include "Dlist.h"
#include "dlistdata.h"
/**************************************************************************************************/
int main(int argc, char* argv[])
{
FILE* ifp, *ofp;
//char outputFilename[] = argv[2];
int hour, min;
int* list;
float temp;
if(argc != 3) /* argc should be 3 for correct execution */
{
/* We print argv[0] assuming it is the program name */
printf("usage: %s filename", argv[0]);
}
else
{
// We assume argv[1] is a filename to open
ifp = fopen(argv[1], "r");
if(ifp == 0)
{
printf("Could not open file\n");
}
else
{
ofp = fopen(argv[2], "w");
}
}
}
void dlist_init(Dlist* list, void (*destroy)(void* data))
{
list->size = 0;
list->destroy = destroy;
list->head = NULL;
list->tail = NULL;
return;
}
I also have the following headers:
dlinklist.h
/**************************************************************************************************/
#ifndef DLIST_H
#define DLIST_H
#include <stdlib.h>
#include "DlistElmt.h"
#include "Dlist.h"
#include "Dlistdata.h"
/**************************************************************************************************/
#endif
Dlist.h
/**************************************************************************************************/
#ifndef DLIST_H
#define DLIST_H
#include <stdlib.h>
#include "dlinklist.h"
#include "DlistElmt.h"
#include "Dlistdata.h"
/**************************************************************************************************/
typedef struct Dlist_ {
int size;
int (*match)(const void *key1, const void *key2);
void (*destroy)(void *data);
DlistElmt *head;
DlistElmt *tail;
} Dlist;
#endi
dlistdata.h
/**************************************************************************************************/
#ifndef DLISTDATA_H;
#define DLISTDATA_H;
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "dlinklist.h"
#include "DlistElmt.h"
#include "Dlist.h"
/**************************************************************************************************/
void dlist_init(Dlist *list, void (*destroy)(void *data));
#endif
DlistElmt.h
/**************************************************************************************************/
#ifndef DLISTELMT_H
#define DLISTELMT_H
#include <stdlib.h>
#include "dlinklist.h"
#include "Dlist.h"
#include "Dlistdata.h"
/**************************************************************************************************/
typedef struct DlistElmt_ {
void *data;
struct DlistElmt_ *prev;
struct DlistElmt_ *next;
} DlistElmt;
/**************************************************************************************************/
#endif