Monday, 18 March 2013

Solution: Access Variables in Different C files

To access variables in different C files, check below example

header.h 
extern int a;

file1.c
#include</root/path/header.h>
int a;
a = 20;

file2.c
#include</root/path/header.h>
printf("a value is %d",a);

Note: if you compile individual file and check then you may get error 
Compile like:
gcc file1.c file2.c -o out
./out
Output: a value is 20

Share This!



No comments:

Post a Comment

Here We Write The Problems we face at different situations and Solutions to those problems.