• Partager sur Facebook
  • Partager sur Twitter

uper to lower letters in c ++?.

    8 novembre 2019 à 14:45:35


    I start with Programming and C ++

    I want to Write a function that reverses a string in-place and upcases every other character.

    "abc" => "CbA"

    a beginner in programming, I try to invert words and turn others into uppercase 



    • Partager sur Facebook
    • Partager sur Twitter
      8 novembre 2019 à 21:49:44

      Hello, it's easy to find a solution online for each function case so here's a example

      I'm not very good in C++ so it can still be better

      // Example program
      using namespace std;//mostly good c++ programmers don't like declaring this 
      //but i prefer because i don't like to use std:: (ex : std::string s = "example")
      #include <iostream>
      #include <string>
      //Will upcase every character in difference between the first string and the second
      void upCaseNonDifference(string& str, string str2){
      for(int i=0;(unsigned)i<str.length();i++){
          if (str[i] != str2[i]){
              str[i] = toupper(str[i]);   
      //reverse the string given in parameter
      void reverseStr(string& str) 
          int n = str.length(); 
          // Swap character starting from two 
          // corners 
          for (int i = 0; i < n / 2; i++) 
              swap(str[i], str[n - i - 1]); 
      //upcase the difference between the given string and his reverse
      void reverseAndUpCaseNonDifference(string& str){
          string str2 = str;
      int main()
      string s = "this , good , test";
      cout << "Originally :" << s << endl;
      cout << "After .... :" << s;

      I Edited my code after I noticed that i misunderstood your message.

      Edité par coukil 8 novembre 2019 à 23:26:32

      • Partager sur Facebook
      • Partager sur Twitter

      uper to lower letters in c ++?.

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      • Editeur
      • Markdown