A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

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

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

0

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

All Answers

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

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

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

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now