I’m working on a linked list for school and I am getting a ton of errors. I’m sure there’s probably only one thing wrong with my code, but I can’t seem to find it. I’ve commented out most of my code so I didn’t have to paste like 200 lines in here and the main error is still showing up, although quite a few less times.
The error is:
error C2143: syntax error : missing '{' before '*'
I had probably 50-75 errors pop up along those guidelines before I commented out my code, but there are still a few with this code. Any help would be much appreciated.
//main.c
#define BUFFER_SIZE 1000
#include<stdio.h>
#include<stdlib.h>
#include"ListElmt.h"
#include"List.h"
#include"ListData.h"
int main(int argc, char *argv[]){
}
//List.c
#include<stdlib.h>
#include"List.h"
#include"ListElmt.h"
#include"ListData.h"
//List.h
struct List{
int size;
struct ListElmt *head;
struct ListElmt *tail;
};
//ListData.h
struct ListData {
int hour;
int min;
double temp;
int AC;
};
//ListElmt.h
struct ListElmt {
ListData *data;
ListElmt *next;
ListElmt *prev;
};
You need to forward declare structures if they aren’t declared in the header file.
Therefore,
List.hneeds a forward declaration ofstruct ListElmt, andListElmt.hneeds a forward declaration ofstruct ListData.Furthermore, in C you have to use
structbeforeListDataandListElmtinListElmt.hsince struct names aren’t considered type names unless you use an explicittypedef.