Count number of digits, alphabets & special characters

C program to read a string and count total number of digits, alphabets and special characters.

Solution:

#include <stdio.h>
int main()
{
    char string[100];
    int a, d, o, i;

    a = d = o = i = 0;
    /* Reads a string from user. Max size of string is 100*/
    printf("Enter any string : ");
    gets(string);
    /* Checks each character of string */
    while(string[i]!='\0')
    {
        if((string[i]>='a' && string[i]<='z') || (string[i]>='A' && string[i]<='Z'))
        {
            a++;
        }
        else if(string[i]>='0' && string[i]<='9')
        {
            d++;
        }
        else
        {
            o++;
        }
        i++;
    }
    printf("Alphabets = %d\n", a);
    printf("Digits = %d\n", d);
    printf("Special characters = %d\n", o);
    return 0;
}


Output:

digits alphabets special characters