The camel case character present in a given string


The aim of this article is to implement a program to print the number of camel case character present in a given string.

As you all know, a string is a collection of characters. Now let us see what camel case letters are.

Programming languages like Java utilise a naming style called camel case. That is, It includes entering multi-word identities without spaces or underscores, having the initial word in lowercase with successive words in uppercase. Code written in this manner is easier to read and understand.

The inner uppercase letters, which resemble camel humps, are what give the name of the font its meaning. WordPerfect, FedEx, and ComputerHope are a few examples of camel case characters.

In addition to this, camel case refers to the absence of spaces or punctuation while writing compound words or sentences. Instead, each distinct word is denoted by either using lowercase or uppercase letters (such as, PlayStation).

The total amount of capital characters in the provided string is the definition of the camel case character.

Sample Example 1

Let us take the input string str = “asKKVrvAN"
The output we get is 2.

Explanation

The Camel case characters that are present in the given string str are K, K, V, A and N.

Sample Example 2

Let us take the input string str = “fhgUBHII”
The output we get is 5.

Explanation

The Camel case characters that are present in the given string str are U, B, H, I and I.

Sample Example 3

Let us take the input string str = “nbdGONYL”
The output we get is 5.

Explanation

The Camel case characters that are present in the given string str are G, O, N, Y and L.

Sample Example 4

Let us take the input string str = “xyz”
The output we get is 0.

Explanation

There are no Camel case characters that are present in the given string str.

Problem Statement

Implement a program to print the number of camel case character present in a given string.

Solution Approach

In Order to to print the number of camel case character present in a given string, we take the following methodology.

The approach to solve this problem and print the number of camel case characters present in a given string is based on ascii values. To the beginners who have little idea on ascii values, here is the definition.

Every character variable is given a number between 0 and 127 as its ascii value, which stands for the value of the variable in numbers.

Uppercase letters A–Z have an ASCII value range of 65–90, while lowercase letters a–z have a value range of 97–122.

That is, the ascii code or the ascii value of the uppercase letter A is 65, B is 65, C is 67 and so on. The letter Z has an ascii value of 90.

Therefore, by iterating through the string provided and counting all the characters wherein ASCII value falls between [65, 91], the stated problem can be resolved. Also once the counting is done, we print the output, that is we print the entire count after making sure all the characters are present.

Algorithm

The algorithm to print the number of camel case character present in a given string is given below

  • Step 1 − Start

  • Step 2 − Define a string

  • Step 3 − set the count to number zero

  • Step 4 − Traverse the string to check the ascii value

  • Step 5 − If the ASCII value of the letter

    • lies in between the range [65, 90] then we increment the count otherwise ignore.

  • Step 6 − Take the total count of Camel case characters obtained and print the output

  • Step 7 − Stop

Example: C Program

Here you can find the C program implementation of the above written algorithm to print the number of camel case character present in a given string.

#include <stdio.h>
#include <string.h>  
int main(){
   char str[]= "abcdEFGH";
   // Stores the total number of camel case letters count is set to 0
   int count = 0; 
   // Traversing the string 
   for (int i = 0; str[i]; i++) { 
      // Check whether ASCII value of the //letter 
      // lies in between the range [65, 90]
      // then we increment the count
      if (str[i] >= 65 && str[i]<=90)
      count++;
   }
   // Print the output as the total count of camel case letters acquired 
   printf("total count of camel case letters acquired: ");
   printf("%d",count);
   return 0;
}

Output

total count of camel case letters acquired: 4

Conclusion

Likewise, we can print the number of camel case characters present in any given string. The challenge of obtaining the number of camel case characters present in a given string is resolved in this article. Here C programming code as well as the algorithm to print the number of camel case characters present in a given string are provided.

Updated on: 28-Jul-2023

383 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements