Hi, my function checks how many words are in the string,the iterative version of this function works perfect & it was too easy to do it, but with recursive ver. I have some problems - I can't understand where I do mistake
thank's
Iterative code
Code:
int CountWords(char text[])
{
int i = 0, j = 0, k = 0;
while(text[i])
{
if(text[i]!=' ')
{
if(!k)j++;
k=1;
}
else
{
k=0;
}
i++;
}
return j;
}
Recursive version :
Code:
int RecCountWords(char text[])
{
int i = 0;
if(text[i] == '/0')
return 0;
else
if(text[i] = ' ')
{
for(; text[i] = ' ';)
{
i++;
}
return (1 + RecCountWords(text + i));
}
else
RecCountWords(text + i);
}