Wednesday, 25 May 2011

Program to count words and characters in a sentence

#include<stdio.h>
#include<conio.h>
void main()
{
 int wordcnt=0;
 int charcnt=0;
 char ch;
 clrscr();
 printf("Type a sentence: ");
 while((getche()) != '\r')
  {
   charcnt++;
   if(ch==' ')
   wordcnt++;
  }
 printf("\nTotal characters are: %d",charcnt);
 printf("\nTotal words are: %d",wordcnt+1);
 getch(); 


}

0 comments:

Post a Comment