I'm writing a program in which one of my functions will only do something if the function has already been called at least once. I want to do this by passing a static int, which is declared in main (I can't use global variables) into the function. I'm not sure if I need to pass this by reference or do anything special in main in order to do this. Can anyone help?
You don't need to (and probably shouldn't) pass in the variable from main. Just put the variable in the function:
1 2 3 4 5 6 7 8 9 10 11 12
void yourfunction()
{
staticbool first_time_called = true;
if( first_time_called )
{
// do whatever you want to do here the first time this function is called
first_time_called = false;
}
// do whatever you want to do EVERY time the function is called here.
}