0

Hi , Inside a recursive function i have a static variable, when i return that static variable , it's value becomes zero.
count = trimWS(someXMLNode);
i get count as 0 , but when i debug countWS was 9.
Pls help me why this is happening and what is the right way to return some value from recursive function.

example :

int trimWS(xmlNode pNode) {
   static int countWS;
   //trimming leading whitespaces
   if(pNode == 0) {
        return countWS;
   }
   while(pNode->name[0] != 0) {
        if( pNode->name[0] == 9 || pNode->name[0]== 10 || pNode->name[0]== 13                     || pNode->name[0]== 32) {
                  (pNode->name)++;
                  countWS++;
       }else {
           break;
   }
   trimWS(pNode->FChild);
}
2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by ppallavi
0

Hmm.

I think you missed out a return statement on the last line.

...
break;
}
return trimWS(pNode->FChild)
}

which means that the function is just returning something that happens to be on the stack when it finishes executing.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.