-
varaible trouble
i have got multiple .c files, and i wish to use the same variable throughout the files. "i" the variable, is used as a counter of members in the array. how do i delclare or initialise this variable so that i can use it in all of the .c files? when i delcare the varibale in each file i get erros saying that it has allready been declared in the other files, and, wheni dont declare it, i get errors messages tellgn me i need to declare it. any ideas people? cheers.
-
Declare i as a global variable in one of your modules and then extern it to the other modules.
In main.c:In remaining .c files:
-
In one file, and only one file declare your variable as you normally would. In all other files, add the word "extern" in front of your variable. As an example:
File1:
#include ?????
#include ?????
int i;
int main()
{
}
File2:
#include ?????
extern int i;
function1()
{
}
function2()
{
}
File3:
#include ?????
#include ?????
#include ?????
extern int i;
function3()
{
}
function4()
{
}
function 5()
{
}
This should give you a hint as to how to proceed.
-
external
I think this should work:
Globally in the main file:
int iSomething = 0;
In all files which should share this instance:
extern int iSomething;
-
I'm just too fast for you guys :p
-
Yeah..
You get a quick response on this board....