Counting words in a String

#include<cstring>
#include<iostream>
using namespace std;
int main()
{
int word=0;
char sent[200];
cout<<"Enter a Sentence:\n";
fgets(sent,200,stdin);
for(int a=0;a<200;a++)
{
if(sent[a]==' ')
{
word++;
}
}
cout<<"The Total Words in a entered sentence are: "<<word;
return 0;
}
And? Do you have a question? A problem?
Topic archived. No new replies allowed.