How to count alphabets, numeric and special characters ?
In this example, we have to count digits, spaces, special characters and alphabets using C program.
#include <stdio.h>
int main()
{
char str[100];
int countDigits,countAlphabet,countSpecialChar,countSpaces;
int counter;
//assign all counters to zero
countDigits=countAlphabet=countSpecialChar=countSpaces=0;
printf("Enter a string: ");
gets(str);
for(counter=0;str[counter]!=NULL;counter++)
{
if(str[counter]>='0' && str[counter]<='9')
countDigits++;
else if((str[counter]>='A' && str[counter]<='Z')||(str[counter]>='a' && str[counter]<='z'))
countAlphabet++;
else if(str[counter]==' ')
countSpaces++;
else
countSpecialChar++;
}
printf("\nDigits: %d \nAlphabets: %d \nSpaces: %d \nSpecial Characters: %d",countDigits,countAlphabet,countSpaces,countSpecialChar);
return 0;
}
Output :
Enter a string: wikitechy, 789@#%12.
Digits: 5
Alphabets: 9
Spaces: 1
Special Characters: 5
Categorized in:
Tagged in:
Accentur interview questions and answers, Applied Materials interview questions and answers, Asian Paints Ltd. interview questions and answers, Bosch India Software interview questions and answers, c program to check special characters, c program to count number of characters in a string, c program to count number of words spaces characters digits and special symbols, c program to find special characters in string, Capgemini interview questions and answers, CASTING NETWORKS INDIA PVT LIMITED interview questions and answers, CGI Group Inc interview questions and answers, Chetu interview questions and answers, Ciena Corporation interview questions and answers, Collabera Technologies interview questions and answers, Dell International Services India Pvt Ltd interview questions and answers, DHFL Pramerica Life Insurance Company Ltd interview questions and answers, Elico HealthCare Services Ltd interview questions and answers, Flipkart interview questions and answers, HCL Technol interview questions and answers, IBM interview questions and answers, Indecomm Global Services interview questions and answers, Mavenir interview questions and answers, Mphasis interview questions and answers, NetApp interview questions and answers, number or special character in c++, Oracle Corporation interview questions and answers, PeopleStrong interview questions and answers, R Systems interview questions and answers, Raqmiyat Information Technologies Pvt Ltd interview questions and answers, Reliance Industries Ltd interview questions and answers, SAP Labs India Pvt Ltd interview questions and answers, Tata AIA Life Insurance interview questions and answers, Tech Mahindr interview questions and answers, The Linde Group interview questions and answers, write a c program to check whether a character is uppercase or lowercase alphabet, write a c program to check whether an alphabet is a vowel or consonant, write a program to check whether an input character is digit or not, write a program to check whether the given input is alphabet, ziynx interview questions and answers