Q:

C Program to count number of alphabets, digits and special characters in string.

belongs to collection: C language string programs

0

C Program to count number of alphabets, digits and special characters in string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to compare two strings using strcmp... >>
<< C program to reverse a string enter by user....