This program is a simple program that takes a string as input and counts the number of alphabets, digits and special characters in the string.
The program starts by including the stdio.h header file, which contains the declarations of the functions used in the program.
In the main function, the program declares a character array "str" of size 100 , an integer variable "i" for the loop, an integer variable "a" to store the count of alphabets, an integer variable "d" to store the count of digits, and an integer variable "s" to store the count of special characters.
It uses the printf function to prompt the user to enter the string and uses the gets function to read the input and store it in the "str" array.
The program then uses a for loop to iterate through the string. Inside the loop, it uses if-else statements to check if the current character is an alphabet, a digit, or a special character. The check is done by comparing the ASCII value of the current character with the range of ASCII values of alphabets, digits and special characters . If the current character is an alphabet, it increments the variable a. If it's a digit, it increments the variable d, otherwise it increments the variable s.
Finally, the program uses the printf function to print out the total number of alphabets, digits, and special characters and returns 0 to indicate that the program has executed successfully
/* 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
Enter The String : Tutor joes @ 2014 Total Alphabets : 9 Total Digits : 4 Total Special : 5
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions