I want to declare a structure in a header file so I can use it in my source file. What am I doing wrong? I want to be able to access my struct 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);
}
Replace:
#include <info.h>
with,
#include "info.h"
With <>
compiler only searches for the header file in predesignated header folder. This is used for standard library header files.
With ""
compiler first searches the header file in the local directory where your .c file is located. This is used for user defined header files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With