Reputation: 25
I'm getting a ton of syntax errors on some C code I wrote and I wasn't sure why. I decided to try recreating a project I had stored on replit and it wouldn't run correctly. I'm not entirely sure why.
#ifndef HEADER_H
#define HEADER_H
// Macros
// Definitions
// Structs
typedef struct Notecard {
char* topic;
char* question;
char* answer;
}Notecard;
typedef struct List {
Notecard* list;
int length;
int capacity;
void (*insert) (List* list, struct Notecard value);
}List;
typedef struct Node {
Notecard card;
Node* next;
}Node;
typedef struct LinkedList {
Node* head;
void (*append) (LinkedList* linked, Node n);
void (*printList) (LinkedList* linked);
}LinkedList;
// Function Declarations
void insertion(List* arr, Notecard value);
void append(LinkedList linked, Node n);
void printList(LinkedList linked);
#endif // !HEADER_H
The first error out of a giant list it is giving me is sayingf that "void (*insert) (List* list,.. ect requires a semicolon after the List*. Is this an issue with Vs?
Upvotes: 0
Views: 120
Reputation: 7
Hello I compiled your code and below is how it should be
#ifndef HEADER_H
#define HEADER_H
// Macros
// Definitions
// Structs
typedef struct Notecard {
char* topic;
char* question;
char* answer;
}Notecard;
typedef struct List {
Notecard* list;
int length;
int capacity;
void (*insert) (struct List* list, struct Notecard value);
}List;
typedef struct Node {
Notecard card;
struct ode* next;
}Node;
typedef struct LinkedList {
Node* head;
void (*append) (struct LinkedList* linked, Node n);
void (*printList) (struct LinkedList* linked);
}LinkedList;
// Function Declarations
void insertion(List* arr, Notecard value);
void append(LinkedList linked, Node n);
void printList(LinkedList linked);
#endif // !HEADER_H
Upvotes: 0
Reputation: 328
List*
is not defined yet since u r still inside its definition when the line void (*insert) (List* list, struct Notecard value);
is executed.Therefore, List* list
will not work.
You have to still put struct List* list
there to make it work.
Upvotes: 2