header - C language, proper usage of include guards -


i'm trying create header file (that include functions wrote avl trees) having slight problem , misunderstanding syntax of include guards.

right code looks this

#ifndef stdio_h #define stdio_h #endif #ifndef stdlib_h #define stdlib_h #endif #ifndef conio_h #define conio_h #endif 

problem is, think includes <stdio.h>. when try use malloc, says malloc undefined, though included stdlib.

according http://www.cprogramming.com/reference/preprocessor/ifndef.html if understood correctly, ifndef checks if token defined, , if isnt, defines write after ifndef , until #endif. code should work.

is stdio defined? no. define it. endif. stdlib defined? no. define it. endif. conio defined? no. define it. endif. don't see problem.

what correct syntax if want add 3 headers?

include guards used prevent double definition in case include file included more once.

the standard include files have necessary include guards, need no include guards them.

your code should be:

#include <stdio.h> #include <stdlib.h> #include <conio.h> 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -