Pages

Subscribe:

Word and Character Count

This C program counts number of words and characters in a string.

Example

  • " hello world " is a string.
  • No of word in a string : 2
  • No of character in a string :10

Program :

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char ch;
do{
    char a[20];
       int i,w=1,c=0;
    clrscr();
     printf("Enter a string:");
     gets(a);
     strlwr(a);
     for(i=0;a[i]!=NULL;i++)
     {
        if(a[i]==' '&& a[i+1]!='.')
        w++;
        if(a[i]>='a' && a[i]<='z')
        c++;
     }
     printf(" No of Word in a String : <%d>",w);  // Check next character [i+1]
     printf(" No of Character in a String : <%d>",c);
     printf("\n Continue(y/n):");
     ch=getch();
}while(ch=='y'||ch=='Y');
}

Output :








If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
                                                           AND

 If you like this article , like our Facebook like page and click  +1 to support 123techguide
comments powered by Disqus
 

Listed In

Bloggers - Meet Millions of Bloggers http://Link-exchange.comxa.com
Blog Search: The Source for Blogs Internet Blogs

Disclaimer

The contents in this blog are taken from various sources available over the internet, therefore we do not gurantee of it's accuracy, if you find any of the content in the blog is infringing it's copyright, please do email us on '123techguide@gmail.com' and we will make sure to remove the same from the blog at the earliest.