in MicroC compiler, i have a challenge with "#include".
i want to add one file to my main programs. my files are: main.c, ds1307.c .
i added ds1307.c file in main.c file with include:
#include "ds1307.c"
but after that i click build, cpp.err appeared with this purporst:
Code:
e:/mikroelektronika/mikroc v8.0/usser/project1/main.c:2: error: Can't open include file "ds1307.c"
#include "ds1307.c"
from e:/mikroelektronika/mikroc v8.0/usser/project1/ds1307.c: 1: #include "main.c"
from e:/mikroelektronika/mikroc v8.0/usser/project1/main.c: 2: #include "ds1307.c"
from e.......
It looks like you also have a #include "main.c" in the file ds1307.c which is a big no-no because you have created a infinite recursive loop. Remove the #include "main.c" statement from the file ds1307.c
another question,
i have a lot of variables that common between two files. i want to Declare those as global variable. how and where i must declare these variables?
I'm not familiar with MicroC, so I'd left the answer to others.
In C, one way to use global variables is to declare them in a separate file called globals.c and then use the extern keyword in header files to give main.c etc access to them. A quick Google turned up this: Learn C++ - » 4.2 — Global variables