#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.
Friday, February 27, 2009
Subscribe to:
Post Comments (Atom)
But how to input the string
ReplyDeleteits given there....enter the required lines of text
ReplyDeleteHow to find result ,It's Only take input
ReplyDeleteI need a c++ program to read a line of text from the keyboard and display the number of words and characters
ReplyDeleteIt's not showing any result.It only takes input
ReplyDeleteEOF not defined
ReplyDeletewhy to use EOF ?
ReplyDelete