Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,988 questions

51,933 answers

573 users

How to extract capital letters from a string in C++

2 Answers

0 votes
#include <iostream>

#define BUFFER_SIZE 64 
 
void extractCapitalLetters(std::string str, char *buf) {
    size_t idx = 0;
     
    if (!buf || str == "") { 
        std::cout << "error: invalid parameter.\n";
        return;
    }
 
    for (int i = 0; i <  str.length(); i++) {
        if (str[i] >= 'A' && str[i] <= 'Z') {
            buf[idx++] = str[i]; 
        }
    }
}
 
int main ()
{    
    std::string str = "C++ is a High-leveL General-purpose pRogramMing LanguagE";
    char capital_letters[BUFFER_SIZE] = "";
 
    extractCapitalLetters(str, capital_letters);
 
    std::cout << capital_letters;
}
 
   
   
    
/*
run:
      
CHLGRMLE
    
*/

 



answered Mar 14, 2024 by avibootz
0 votes
#include <iostream>

#define BUFFER_SIZE 64 
 
std::string extractCapitalLetters(std::string str) {
    if (str == "") { 
        std::cout << "error: invalid parameter.\n";
        return "";
    }
    
    std::string capital_letters = "";
 
    for (int i = 0; i <  str.length(); i++) {
        if (str[i] >= 'A' && str[i] <= 'Z') {
            capital_letters += str[i]; 
        }
    }
    
    return capital_letters;
}
 
int main ()
{    
    std::string str = "C++ is a High-leveL General-purpose pRogramMing LanguagE";

    std::string capital_letters = extractCapitalLetters(str);
 
    std::cout << capital_letters;
}
 
   
   
    
/*
run:
      
CHLGRMLE
    
*/

 



answered Mar 14, 2024 by avibootz
...