While using a global would work, it's a bad idea. Change the function to take a pointer to an int for the flag argument, then pass the address of the flag argument in main and set the flag like this...