belongs to collection: C language string programs
C Program to count number of alphabets, digits and special characters in string.
Solution:
I have used Code:: Blocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
#include <stdio.h> #define MAX_SIZE 100 int main() { char string[MAX_SIZE]; int alphabets, digits, specialchars, i; alphabets = digits = specialchars = i = 0; printf("Enter any string : "); gets(string); while(string[i]!='\0') { if((string[i]>='a' && string[i]<='z') || (string[i]>='A' && string[i]<='Z')) { alphabets++; } else if(string[i]>='0' && string[i]<='9') { digits++; } else { specialchars++; } i++; } printf("Total Alphabets : %d\n", alphabets); printf("Total Digits : %d\n", digits); printf("Total Special characters : %d\n", specialchars); return 0; }
Result:
Enter any string : techstudy@123
Total Alphabets : 9
Total Digits : 3
Total Special characters : 1
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Solution:
I have used Code:: Blocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
Result:
Enter any string : techstudy@123
Total Alphabets : 9
Total Digits : 3
Total Special characters : 1
need an explanation for this answer? contact us directly to get an explanation for this answer