Your Ad Here

Friday, February 27, 2009

Write a C++ program to count the lines, words and characters in a given text.

#include(iostream.h)
#include(conio.h)
#include(stdio.h)
void main( )
{
char ch;
int sp=0, ct=0, line=0;
clrscr( );
cout<<"Enter the required lines of text:";
while((ch=getchar())!=EOF)
{
ct++;
if((ch==' ')
sp++;
if(ch=='\n')
line++;
}
cout<<"Total Lines:"<< line;
cout<<"Total words:"<< sp+line;
cout<<"Total Characters:"<< ct;
getch( );
}

Output:- Enter the required lines of text:
Where are you
Come fast
^z

Total Lines: 2
Total words: 5

Note:- If u have any doubt regarding this program or logic, please feel free to contact me.

7 comments:

  1. its given there....enter the required lines of text

    ReplyDelete
  2. How to find result ,It's Only take input

    ReplyDelete
  3. I need a c++ program to read a line of text from the keyboard and display the number of words and characters

    ReplyDelete
  4. It's not showing any result.It only takes input

    ReplyDelete