My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program to count characters, words and lines in the string

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
 char a[100];
 int ch=0,w=0,l=0;
 cout<<"enter the string"<<endl;
 cin.get(a,100,'*');
 for(int i=0;a[i]!='\0';i++)
 {if(a[i]=='\n')
 { i++,w++;}
  if(a[i]==' ')
  w++;
  ch++;
  }
  cout<<"number of characters: "<<ch<<endl;
  cout<<"number of words: "<<w+1<<endl;
  cout<<"number of lines: "<<l+1<<endl;
  getch();
  }

0 comments: