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


Introduction

C Program to count number of alphabets, digits and special characters in string. I have used Code:: Blocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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

C language

     





Related Topics




Popular Posts