I have a project that requires different types of iterations. One is function recursion on a char array of 5000. After 50 calls it will crash, assuming from stack overflow. Not sure how to get around this.
void functionLoop(int loopInt)
{
#ifdef ___EXSTR_H___
#undef ___EXSTR_H___
#endif
#include "exstr.h"
ofstream fout;
fout.open("output.txt");
int arrayLength = sizeof ( example_strings ) / 4; // arrayLength = 5000.
char *stringArray = example_strings[loopInt];
int charCount = 0;
while( *stringArray != 0 )
{
stringArray++;
charCount++;
}
cout << loopInt + 1 << ": " << charCount << ": " << example_strings[loopInt] << endl;
loopInt++;
if(loopInt < arrayLength)
{
functionLoop(loopInt);
}
}
EDIT:
I cleaned up the code a lot, got rid of all the variables, moved the header file to a parameter, and gained about 4500 more iterations, but it’s still crashing after 4546. Here’s the updated code:
void functionLoop(char * example_strings[], ofstream &outputFile, int counter)
{
outputFile << counter + 1 << ": " << strlen(example_strings[counter]) << ": " << example_strings[counter] << endl;
counter++;
if(counter < ARRAY_SIZE)
{
functionLoop(example_strings, outputFile, counter);
}
}
Thank you to everyone that helped.
Pass the array as a parameter to your function, i.e.