After looking at the code again. I think i got a problem with it again.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <ctype.h>
int main()
{
char str[50];
int i=0,count=0;
int space = 0;
int len = 0;
int inWord = 0;
printf("Enter a string : ");
// gets(str);
strcpy(str,"Testing one two three four");
printf("%s",str);
while(str[i]!='\0')
{
if((str[i]== ' ' && str[i+1]!= ' ' && inWord++ ))
count++;
i++;
}
printf("\n\nThe total number of words are %d ", count);
while(str[len]!='\0') len++;
for(i=0;i<=len;i++)
{
while( isspace( str[i] )) { space++; i++; }
{continue;}
}
printf("\n\nThe total number of spaces are %d ",space);
printf("\n\n");
system("pause");
return 0;
}
input: [space]Testing one two three[space]
output: 4 words
But
input:Testing one two three
ouput: 2 words
I think i'm getting confuse with the coding.