Need to fix my minimum function

Hello is a formality on all the post maybe putting it should help get replies. I have a function that outputs the minimum number of a certain function kind of here is a quick look at the code.


void mini(int place,long int number)
{
long int array[15];

//then a for loop to clear the array when place==-1.

if (place>-1)&&(array[place]>number || array[place]==0)
{array[place]=number;}

//then a for loop to display all data in the array when place==-2.
}


void another function()
{
//random number generator this number is the same number needed in
//the second part of the function above variable is called Temp.

//take that number and do some stuff to get a integer less than 15 but
//never negative for place variable is called persistence.

mini(persistence, Temp);
}




int main()
{
mini(-1,0);

for(lots of times)
{another function();}

mini(-2,0);
return 0;
}

--------------------
So the issue is then I call mini at the end it only holds data from the last another function() that was run instead of all of them that ran. I need help I have no idea what I could do.
Last edited on
your array is not static, so it is created on the stack every time mini() is called and destroyed every time the function exits. If it happen to contain data that was created during the previous run of anotherfunction(), that is merely fortuitous reuse of the same block of memory.

If you declare static long int array[15]; the memory will remain intact between calls to anotherfunction().

You are the best. Thank you so much. =)
Topic archived. No new replies allowed.