So I have created couple of files:
file1.c
#include "file2.h"
...
int *p; <-GLOBAL VARIABLE
...
void main(){
printer();
}
file2.c
#include "file1.h"
void printer(){
*p = 5;
printf("%d",*p);
}
file1.h
extern int *p;
file2.h
extern void printer(void);
Code compiles. However, when I run it, I get segmentation error. I have tried to look for the solution everywhere, but couldn't find a good one.
I tried replacing printer(void) in file2.h with printer() no result (and not sure if it is correct, either).
Does anyone possibly see a solution to my issue?
extern. Any files that use that global variable can access it by #include the header file and then using the variable as if it were local to the current .c file.