ADVERTISEMENT
ADVERTISEMENT

C program to count upper case and lower case characters in a string

This c program will read a string and count total number of uppercase and lowercase characters in it. To test, which is lowercase or uppercase character, we need to check that character is between ‘A’ to ‘Z’ (Uppercase character) or ‘a’ to ‘z’ (Lowercase character).

Example:

    Input string: This is a Test String.

    Output:
    Total Upper case characters: 3, 
    Lower Case characters: 14

Program:

/*C program to count uppercase and lowercase 
characters in a string.*/

#include <stdio.h>

int main()
{
    char str[100];
    int countL, countU;
    int counter;

    //assign all counters to zero
    countL = countU = 0;

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

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

        if (str[counter] >= 'A' && str[counter] <= 'Z')
            countU++;
        else if (str[counter] >= 'a' && str[counter] <= 'z')
            countL++;
    }

    printf("Total Upper case characters: %d, Lower Case characters: %d", countU, countL);

    return 0;
}

Output

    Enter a string: This is a Test String.
    Total Upper case characters: 3, Lower Case characters: 14

C Strings User-defined Functions Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.