Counting words in a String

May 27, 2015 at 4:52am
#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;
}
May 27, 2015 at 10:16am
And? Do you have a question? A problem?
May 27, 2015 at 11:37am
Topic archived. No new replies allowed.