Q:

C Program to count upper case, lower case and special characters in a string

0

C Program to count upper case, lower case and special characters in a string

All Answers

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

#include<stdio.h>
 
int main()
{
    char text[100];
    int i;
    int countL,countU,countS;
     
    printf("Enter any string: ");
    gets(text);
 
    
    printf("Entered string is: %s\n",text);
     
   
    countL=countU=countS=0; 
     
    for(i=0;text[i]!='\0';i++)
    {
        
        if((text[i]>='A' && text[i]<='Z') || (text[i]>='a' && text[i]<='z'))
        {
            if((text[i]>='A' && text[i]<='Z'))
            {
               
                countU++;
            }
            else
            {
               
                countL++;
            }
        }
        else
        {
          
            countS++; //it is special character
        }
    }
     
    
    printf("Upper case characters: %d\n",countU);
    printf("Lower case characters: %d\n",countL);
    printf("Special characters: %d\n",countS);
     
    return 0;
}

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now