1) Use globals, as you've done:
Code:
#include stuff here
int myglobal;
void fun( void )
{
myglobal = 10;
}
void showglobal( void )
{
printf("myglobal is %d", myglobal );
}
int main( void )
{
myglobal = 4;
showglobal();
fun();
showglobal();
myglobal--;
showglobal();
return 0;
}
That's a poor way to do it. But some times, used sparingly, it works out ok.
2) Pass the variable via function calls:
Code:
#include stuff here
void somefunction( int x )
{
printf("x is %d\n", x );
}
void someotherfunction( int *x )
{
printf("x is %d, ", *x );
*x = 234;
printf("but now it's %d!\n", *x );
}
int yetanotherfunction( void )
{
printf("Changing your variable via return value...\n");
return 1034;
}
int main( void )
{
int myvariable = 0;
somefunction( myvaraible ); /* available, but won't be modified */
printf("myvariable is %d\n", myvariable );
someotherfunction( &myvariable ); /* available, can be modified */
printf("myvariable is %d\n", myvariable );
myvariable = yetanotherfunction( ); /* modified by the return value */
printf("myvariable is %d\n", myvariable );
return 0;
}
Enjoy.
Quzah.