change lowercase string to uppercase
Dec 18, 2015 at 12:02am UTC
I am writing a function that changes the case of a lowercase string into uppercase. However, it's not doing so. Any help on what I am doing wrong will be appreciated!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
using namespace std;
string changeCase(const string & s);
int main() {
cout << changeCase("blah" ) << endl;
}
string changeCase(const string & s) {
string ret(s);
for (unsigned i = 0; i < ret.size(); i++)
{
if (islower(ret[i])) { toupper(ret[i]); }
}
return ret;
}
Dec 18, 2015 at 12:08am UTC
if (islower(ret[i])) {
ret[i] = toupper(ret[i]);
}
Dec 18, 2015 at 2:39am UTC
1 2 3 4 5 6
#include <algorithm>
string changeCase(const string & s) {
string ret(s);
std::transform(ret.begin(), ret.end(), ret.begin(), ::toupper);
return ret;
}
Topic archived. No new replies allowed.