Sunday, 20 July 2014

How to Count Words of String in C++

Structure of the Problem Requirements

In this Problem we Count the Number of words in a String Given by user . The Program get Input a String from user and then count the Number of word contain that String . A Condition on space between the sentence is used to accomplish this task.

Source Code 

using namespace std;
int main( )
//clrscr( );
char str[80];
int words=0;
cout<<"Enter Your Story to Count Words:";

for(int i=0;str[i]!='\0';i++)
if (str[i]==' ')

cout<<"Your Story Consist of  ="<<words+1 <<" Words"<<endl;

return 0;

Output of the Program

C++ String Programming
Count Words of String

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.


Post a Comment