Declare a structure in the header file

I want to declare a structure in a header file so that I can use it in the source file. What am I doing wrong? I want to have access to my structure from any function.

info.h

#ifndef INFO_H #define INFO_H typedef struct info { int mem_size; int start_loc; int used_space; int free_space; } INFO; #endif 

test.c

 #include <stdio.h> #include <stdlib.h> #include <info.h> #define F_first 1 #define F_last 2 #define F_data_int 3 #define F_data_char 4 #define F_data_float 5 #define F_print 6 void * f(int code); int main() { INFO in; in.mem_size = 8; f(F_last, 0,0); return(0); } void * f(int code) { printf("%d", in.mem_size); } 
+7
source share
2 answers

Replace:

 #include <info.h> 

from,

 #include "info.h" 

With <> compiler only looks for the header file in the biased header folder. This is used for standard library header files.
With "" compiler first looks for the header file in the local directory where your .c file is located. This is used for custom header files.

+8
source

Yes ... You should use #include "info.h" instead of #include <info.h"> for custom headers. They are usually not part of the system branch, which are usually located in the /usr/include directory on Unix / Linux platforms.

+1
source

All Articles