I'm having some very hard time with my header files when working with linked lists.
I'm not too sure what I need to define in them except for the prototype functions.
The way to create strucs within the header files confuse me.
This first file is the header for the file that works with the linked lists.
// Created by on 12-03-06.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
#define BOOLEAN int
struct NODE *next;
}*head = 0;
BOOLEAN add(struct NODE *p);
BOOLEAN valid (char username, char password); a
As you can see, I choose to declare the struct in the header file. Is there anything wrong with this?
will not work, because you need to define NODE as struct NODE.
I would highly recommend using a typedef (if you have learned about that) which will help reduce the amount of typing (that way you will only have to write NODE and not struct NODE each time it is required).
I have a slight problem after fixing those problems.
It's starting to complain how my *head is declared in the header file. I include this header into 2 more .c files.
The solution that I tried for this was to take the *head = NULL out and replace it with
extern struct NODE *head;
and initialized it within the .c file. Now its giving me a error I've never seen before.
Undefined symbols for architecture x86_64:
"_head", referenced from:
_add in ccAyvsLn.o
_valid in ccAyvsLn.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
What is the reason for declaring *head in your header file? I'm asking, because it causes complications: since you defined it in the header file, and protected it using #ifdef/#endif, it will not be visible in your other source (C file).
Now a question out of curiosity: what kind of compiler / IDE are you using?