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