Would this be preferrable then? if i only have to declare "i" as an integer in main() once, then how is that any different from using it as a global variable? otherwise i would have to declare "i" as an integer in all 3 of my custome functions if i wanted to use them as a counter?
Also, if the "i" counter in SomeFunction(); is let's say increminted to the value 12 for the loop, the function does whatever it's purpose and then the function ends and main() calls AnotherFunction(); does "i" still = 12 from when I increminted it in the previous function or does i = 0 or some unknown number at this point?
Code:
#include <stdio.h>
void SomeFunction( void );
void AnotherFunction( void );
void YetAnotherFunction( void );
int main( void ) {
int i;
i = 0;
SomeFunction();
AnotherFunction();
YetAnotherFunction();
return 0;
}
void SomeFunction( void ) {
// do i need to do int i; here?
// do i need to do i = 0; here?
// some loop using "i" as the counter here
}
void AnotherFunction( void ) {
// do i need to do int i; here?
// do i need to do i = 0; here?
// some loop using "i" as the counter here
}
void YetAnotherFunction( void ) {
// do i need to do int i; here?
// do i need to do i = 0; here?
// some loop using "i" as the counter here
}