Hello,
I was wondering if it's possible to call the same function within itself? It's a function that searches for a string within a paragraph. I want the function to keep running over and over until the end of the paragraph is reached. I keep getting a Stack Overflow. When I looked that up in the Borland C++ Builder 5.0 help file, one reason is infinite recursion. Could this be it?
Thanks in advance,
Kosta
I was wondering if it's possible to call the same function within itself? It's a function that searches for a string within a paragraph. I want the function to keep running over and over until the end of the paragraph is reached. I keep getting a Stack Overflow. When I looked that up in the Borland C++ Builder 5.0 help file, one reason is infinite recursion. Could this be it?
Code:
void DoSearch(char sString[],char paragrph[LINES][CHARS],int& lne,int& rsult,
int& col,int& row)
{
int i=0,length=0,success=0,temp1=0,temp2=0;
//tests for EOF
if (paragrph[row][0]!='\0')
{
//get length of search string
for (length=0;sString[length]!='\0';length++);
//skip characters till last character of search string is found on line
//also checks for EOF
while ((paragrph[row][col]!=sString[length])&&(paragrph[row][0]!='\0'))
{
col++;
//makes sure next line is started, if needed
if (paragrph[row][col-1]=='\0')
{
row++;
col=0;
}
//accounts for one character being matched
if (paragrph[row][col]==sString[length])
{
success=1;
}
}
//checks in reverse for remaining matching characters
temp1=col-1;
temp2=length-1;
for (i=1;((i<length)&&(temp1>=0)&&(temp2>=0));i++)
{
if (paragrph[row][temp1]==sString[temp2])
{
success++;
temp1--;
temp2--;
}
else
{
success=0;
break;
}
}
//adds to count of matching strings
if (success==length)
{
rsult++;
}
//begins the search again if EOF is not reached
if (paragrph[row][0]!='\0')
{
DoSearch(sString,paragrph,lne,rsult,col,row); //<-- COMPILER POINTS HERE ON OVERFLOW
}
}
return;
} //end of DoSearch
Thanks in advance,
Kosta