C program to count total number of alphabets, digits and special characters in a string using pointers and while loop / सी प्रोग्राम पॉइंटर्स और लूप का उपयोग करके स्ट्रिंग में कुल अक्षर, अंकों और विशेष वर्णों को गिनने के लिए।












C program to count total number of alphabets, digits and special characters in a string using pointers and while loop.




C program to count total number of alphabets, digits and special characters in a string using pointers and while loop.



#include <stdio.h> #define MAX 100 int main() { char text[MAX]; char * st = text; int alphabets, digits, others; alphabets = digits = others = 0; printf("Enter any string : "); gets(text); while(*st) { if((*st >= 'a' && *st <= 'z') || (*st >= 'A' && *st <= 'Z')) alphabets++; else if(*st>='0' && *st<='9') digits++; else others++; st++; } printf("\n Number of Alphabets = %d", alphabets); printf("\n Number of Digits = %d", digits); printf("\n Number of Special characters = %d", others); return 0; }


Output:
Enter any string : computer3136$$ Number of Alphabets = 8 Number of Digits = 4 Number of Special characters = 2





Exercise: 1
Write a C program to find total number of alphabets, digits or special character in a string.