Ad
Fundamentals
Strings

Task: Define a function that takes a string as a parameter and returns it with spaces between each original character

Code
Diff
  • #include <string>
    
    std::string digest(std::string param)
    {
        for (int i = 1; i < param.length(); i += 2)
          param.insert(i, 1, ' ');
        return param;
    }
    • #include <string.h>
    • std::string digest(std::string param) {
    • std::string result;
    • for (int i = 0; sizeof(param); i++) {
    • result += param[i];
    • result += ' ';
    • }
    • return result;
    • } //Please fix!
    • #include <string>
    • std::string digest(std::string param)
    • {
    • for (int i = 1; i < param.length(); i += 2)
    • param.insert(i, 1, ' ');
    • return param;
    • }