C++ Program to Read a Set of Lines





This is a program to read a set of lines and find out the number of characters, word and lines in a given text and display each word of the text in different lines.

#include<iostream.h>

#include<conio.h>

Void main ()

{

Int i=0, linecount=1, wordcount=1;

Char str [100];

Clrscr ();

Cout<<”\n Enter the lines”;

Cin.get (str, 100, ‘#’);

Do

{

If (str[i] ==’’ ?? str [i] ==’\n’)

{

Wordcount++;

}

If (str[i] ==’\n’)

{

Linecount++;

}

I++;

}

While (str[i]! = ‘\o’);

Cout<<”\n the number of characters are”<<I;

Cout<<”\n word count=”<<wordcount;

Cout<<”\n line count=”<<linecount;

Cout<<”\n the entered word are”;

For (int j=o; j<I; j++)

{

If (str [j] ==’’)

{

Cout<<”\n”;

}

Else

{

Cout<<str[j];

}

getch ();

}



Related posts:

  1. C++ Program to Input and Output String This is a simple program which is designed  to take...
  2. C++ Program To Display Result Stored In An Array This program takes ‘n’ number as input , stores it...
  3. C++ Program to Sort Elements This program reads a set of numbers from the standard...
  4. C++ Program using If-else Statement This program shows the simple use of if-else statement. In...
  5. C++ Program showing constructor overloading Constructor is a member function with the same name as...