Static variables in functions
I'm trying to use static variables in a recursive function, but am having a problem. I've got something very loosely like this:
My program is very different than this example shows the problem: how do I make it so counter isn't reset every time the recursive function is called? I haven't tried this program yet (one of the problems with work and school, only time for programming on the weekends. But it seems like every time the next recursive function is called, this would reset counter to garbage once it hits the line "static int counter". If so, any suggestions to get around this?
int recursive(int numOfTimes)
static int counter;
..... // Do some calculations here that increment counter
..... // Do some calculations using counter that depend on
..... // how high counter got in the previous recursive calls