C Program - Write a function that accepts a character as parameter and returns 1 if it is an alphabet, 2 if it is a digit and 3 if it is a special symbol. In main, accept characters till the user enters EOF and use the function to count the total number of alphabets, digits and special symbols entered


Program

#include <stdio.h>
void cal();
int main()
{
cal();
}
void cal()
{
    char    str[100];
    int countDigits,countAlphabet,countSpecialChar,countSpaces;
    int counter;

    countDigits=countAlphabet=countSpecialChar=countSpaces=0;

    printf("Enter a string: ");
    gets(str);

    for(counter=0;str[counter]!=NULL;counter++)
    {

        if(str[counter]>='0' && str[counter]<='9')
            countDigits++;
        else if((str[counter]>='A' && str[counter]<='Z')||(str[counter]>='a' && str[counter]<='z'))
            countAlphabet++;
        else if(str[counter]==' ')
            countSpaces++;
        else
            countSpecialChar++;
    }

    printf("\nDigits: %d \nAlphabets: %d \nSpaces: %d \nSpecial Characters: %d",countDigits,countAlphabet,countSpaces,countSpecialChar);

    return 0;
}

Output:

Enter a string: ARS ProZone

Digits: 0
Alphabets: 10
Spaces: 1
Special Characters: 0

Post a Comment

1 Comments

  1. Casino near Santa Barbara (CA) - Mapyro
    Casino near Santa 과천 출장안마 Barbara (CA) 계룡 출장샵 with 천안 출장안마 location, reviews and information for 정읍 출장안마 Casino near Santa Barbara in 영천 출장안마 Santa Barbara: Casino Near Me. Mapyro

    ReplyDelete