u

Friday 14 September 2012

C++ Program to input any string and print the number of words

C++ Program to input any string and print the number of words

 #include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
main()
{
char a,name[50];
int l=0,c=0,word=0;
cout<<"Enter any string "<<endl;
gets(name);
l = strlen(name);
cout<<endl;
for(int i=0;i<l;i++)
{
a=name[i];
if (a==' ') c = c + 1;
}
word = c + 1;
cout<<"The total number of words in the string is "<<word;
cout<<endl;
getch();
return 0;

}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More