Tuesday, July 28, 2009

In C - How do I write a small program that when called with in integer value displays this value together....?

with the number of times the function has its self been called.





(I've been told I need to use a static variable for this).





Thanks for your help :-)

In C - How do I write a small program that when called with in integer value displays this value together....?
the function would look like





void NumberOfTimesCalled()


{


static int CurrentCount;


CurrentCount++;


printf(" function has been called %d times", CurrentCount);


}





//this main would test it


int main(int args, char *argv[])


{


int i = 0;


for(i = 0; i %26lt; 10; i++)


NumberOfTimesCalled();


return 0;


}

cyclamen

No comments:

Post a Comment