1. ## recursive counting words

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);
}```

2. Originally Posted by poftornik
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);
}```
This should cause a seg fault.

3. a better way to check white space is with the isspace() function.

4. Originally Posted by Kennedy
This should cause a seg fault.
There are many errors there.

1. The nul check should be \0 and not /0
2. == is not =
3. The final else doesn't return any value.
4. Not an error, but why is the incrementing in the loop body instead of the final portion of the for loop?

They need to compile with warnings on.

Quzah.