In my code, in order to find the number of words by counting the number of spaces, I am having a logical error
My intention is to count the number of spaces using a for loop and an 'if' condition. I want the loop to keep going even when the condition given under 'if' is not satisfied, but it isn't working
This is my code:
//counting no of words
int words=0;
int spaces=0;
for (int j=0,m=strlen(s);s[j]<m;j++)
{
if(s[j]==' ')
spaces++;
}
words= (spaces + 1);
printf("%i words\n",words);