Follow us on FB

Saturday, March 1, 2014

Count Words in a String using dev/C++

Now i am trying to count the No of words in a string  using C++ or dev .  You can use this code to count the words . which you enter . this is a simple and easy article , which would help you to learn C++ complicated coding with explanations . 
I am write every code line explanation in front of that line.
after coding running you can get out put as............


Code for this program is below . but ..........
this Code in dev , if you use Turbo C++ then do some Changing...
remove using namespace std;
remove int main  and use void main in turbo C++ .
remove return and use getch() int Turboo C++ .

Code of Programe :

#include <iostream>
#include <conio.h>             //for getche()
using namespace std;
enum itsaWord { NO, YES };     //NO=0, YES=1
int main()
{
itsaWord isWord = NO;       //YES when in a word,
//NO when in whitespace
char ch = 'a';              //character read from keyboard
int wordcount = 0;          //number of words read
cout << "Enter a phrase:\n";
do {
ch = getche();           //get character
if(ch==' ' || ch=='\r')  //if white space,
{
if( isWord == YES )   //and doing a word,
{                  //then it’s end of word
wordcount++;       //count the word
isWord = NO;       //reset flag
}
}                     //otherwise, it’s
else                     //normal character
if( isWord == NO )    //if start of word,
isWord = YES;      //then set flag
} while( ch != '\r' );   //quit on Enter key
cout <<endl<< "---Word count is " << wordcount << "---\n";

return 0;

}


If you feel any problem in program running then post in comment ,
i try my best to resolve this problem ,,,,,,,,,,,
Thanks for Visiting.

Unknown

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.

3 comments:

  1. Replies
    1. Count Words In A String Using Dev/C++ ~ Placeoflearn >>>>> Download Now

      >>>>> Download Full

      Count Words In A String Using Dev/C++ ~ Placeoflearn >>>>> Download LINK

      >>>>> Download Now

      Count Words In A String Using Dev/C++ ~ Placeoflearn >>>>> Download Full

      >>>>> Download LINK US

      Delete

 

Copyright @ 2013 placeoflearn.