C program to count Uppercase, Lowercase, Digit and Special character
In this program, you will take string input from user and finding all occurrence of uppercase, lowercase, digit and special character from a given string.
#include<stdio.h>
int main()
{
char a[30];
int u=0,l=0,s=0,d=0,i;
printf("\nenter the string:");
gets(a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]>='A' && a[i]<='Z')
u++;
else if(a[i]>='a' && a[i]<='z')
l++;
else if(a[i]>='1' && a[i]<='9')
d++;
else{
s++; }
}
printf("\nuppercase:%d",u);
printf("\nlowercase:%d",l);
printf("\ndigit:%d",d);
printf("\nspecial character:%d",s);
return 0;
}
output
enter the string:WeL@@come12 uppercase:2 lowercase:5 digit:2 special character:2