Loading
View RSS Feed

Harsh Chowdhary's Blog

How To Find Number of Vowels, Consonants, Digits, Words and Special Characters in a given String in C?

Rating: 14 votes, 4.29 average.
Here is a C program to find out the number of Vowels, Consonants, Digits, Words and Special Characters in a given String.

Code:
    /***********Prog. for counting different character**********/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 char s[100];
 int b,c,d,e,i,l,p;
 b=c=d=e=0;
 clrscr();
 printf("\n\t Enter the string :=>");
 gets(s);
 l=strlen(s);
 for(i=0;s[i]!='\0';i++)
  {
   if((s[i]>=65&&s[i]<=90||s[i]>=97&&s[i]<=122))
   b++;
   if(s[i]>=48&&s[i]<=57)
   c++;
   if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')
   d++;
      if (s[i]==' ')
   e++;
   }
   p=b-d;
   printf("\n\t No of vowels=%d \n",d);
   printf("\n\t No of consonants=%d \n ",p);
   printf("\n\t No of digits=%d \n",c);
   printf("\n\t no of words=%d \n ",e+1);
   printf("\n\t No of specal character=%d \n",l-b-c-e);
   getch();
}
I have only provided you the code. Ask me for the Explanation. I am always ready to explain it.

The above code is copyrighted.Please do not copy and reproduce the code.

Submit "How To Find  Number of Vowels, Consonants, Digits, Words and Special Characters in a given String in C?" to Digg Submit "How To Find  Number of Vowels, Consonants, Digits, Words and Special Characters in a given String in C?" to del.icio.us Submit "How To Find  Number of Vowels, Consonants, Digits, Words and Special Characters in a given String in C?" to StumbleUpon Submit "How To Find  Number of Vowels, Consonants, Digits, Words and Special Characters in a given String in C?" to Google

Updated 01-09-2011 at 06:45 PM by Harsh

Tags: c language
Categories
C C++

Comments

  1. Unregistered's Avatar
    how can i findd the consonant words??
  2. queng's Avatar
    what do you mean by the values of s[i] like 48, 90, 122 etc.?
  3. Harsh's Avatar
    All these are ASCII values
  4. Malerie's Avatar
    I much prefer inforaimvte articles like this to that high brow literature.
  5. Unregistered's Avatar
    Quote Originally Posted by Harsh
    All these are ASCII values
    please explain the code, thanks
  6. Harsh's Avatar
    This is simple code to track the characters in terms of ASCII range. For specific characters (a,e,i,o,u) the character itself is used in vowels count.



Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.