I'm trying to create a header file (that will include functions I wrote for AVL Trees) but I am having a slight problem and misunderstanding about the syntax of include guards.
Right now my code looks like this
#ifndef STDIO_H
#define STDIO_H
#endif
#ifndef STDLIB_H
#define STDLIB_H
#endif
#ifndef CONIO_H
#define CONIO_H
#endif
problem is, I think it only includes <stdio.h>
. When I try to use malloc, it says malloc is undefined, even though I included stdlib.
According to http://www.cprogramming.com/reference/preprocessor/ifndef.html if i understood correctly, ifndef checks if the token is defined, and if it isnt, it defines everything i write after ifndef and until #endif. So my code should work.
Is stdio defined? no. so define it. endif. is stdlib defined? no. so define it. endif. is conio defined? no. so define it. endif. I don't see the problem.
What is the correct syntax if I want to add those 3 headers?
Include guards are used to prevent double definition in case an include file get included more than once.
The standard include files have the necessary include guards, so you need no include guards for them.
Your code should be:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>