C - Write program to count upper and lower case letter

Requirements

Write program to count upper and lower case letter

Hint

Use ctype functions.

Demo

#include <stdio.h>
#include <ctype.h>

int main()/*from w  ww. j av a  2  s .  c  o  m*/
{
    char phrase[] = "This is a Test.";

    int index;
    int alpha,blank,lower,punct,upper;

    alpha = blank = punct = lower = upper = 0;

/* gather data */
    index = 0;
    while(phrase[index])
    {
        if(isalpha(phrase[index]))
            alpha++;
        if(isblank(phrase[index]))
            blank++;
        if(ispunct(phrase[index]))
            punct++;
        if(islower(phrase[index]))
            lower++;
        if(isupper(phrase[index]))
            upper++;
        index++;
    }

/* print results */
    printf("\"%s\"\n",phrase);
    puts("Statistics:");
    printf("%d alphabetic characters\n",alpha);
    printf("%d blanks\n",blank);
    printf("%d punctuation symbols\n",punct);
    printf("%d lower case letters\n",lower);
    printf("%d upper case letters\n",upper);

    return(0);
}

Result

Related Exercise