Count Alphabets Digits and Special Characters in a String in C


A string is nothing but an array of characters. The value of a string is determined by the terminating character. Its value is considered to be 0.

Source Code

/*
C Program to Count Alphabets Digits and Special Characters in a String
a="ram";
0-r  1-a  2-m 3-\0
*/
#include<stdio.h>
 
int main()
{
    // 65-90  97-122 48-57
    char str[100];
    int i,a=0,d=0,s=0;
    printf("\nEnter The String : ");
    gets(str);
    for(i=0; str[i]!='\0'; i++)
    {
        if((str[i]>=65&&str[i]<=90) || (str[i]>=97&&str[i]<=122))
            a++;
        else if (str[i]>=48&&str[i]<=57)
            d++;
        else
            s++;
    }
    printf("\nTotal Alphabets    : %d",a);
    printf("\nTotal Digits       : %d",d);
    printf("\nTotal Special      : %d",s);
    return 0;
}
 
To download raw file Click Here

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes