Nov 14, 2014 at 8:59am UTC
I have to implement: string tolower(string str) , which lowercases all alphabetic characters in the string.
This code works by itself:
1 2 3 4 5 6 7 8 9
string str = "HELLO" ;
int i = 0;
char c;
while (str[i]) {
c = str[i];
str[i] = tolower(c);
cout << str[i];
i++;
}
However, it won't work when I implement it with the function definition:
1 2 3 4 5 6 7 8 9 10 11
string tolower(string str) {
int i = 0;
char c;
while (str[i]) {
c = str[i];
str[i] = tolower(c);
cout << str[i];
i++;
}
}
Then call using: cout << tolower("HELLO");
Thank you for the help.
Last edited on Nov 14, 2014 at 9:01am UTC
Nov 14, 2014 at 9:06am UTC
You need to return something from your function as it is declared as returning value. Additionally you do not need to output anything in your function at all.
Nov 14, 2014 at 9:36am UTC
Thanks for the advice. I ended up with:
1 2 3 4 5 6 7 8 9 10 11
string tolower(string str) {
int i = 0;
char c;
while (str[i]) {
c = str[i];
str[i] = tolower(c);
i++;
}
return str;
}
But it still isn't working correctly, and I'm not really sure what I should do.
I get this compile error: none of the 2 overloads could convert all the argument types
Last edited on Nov 14, 2014 at 9:38am UTC
Nov 14, 2014 at 9:39am UTC
It would be more helpful if you posted the full error message.
Nov 14, 2014 at 9:42am UTC
Here it is:
error C2665: 'tolower' : none of the 2 overloads could convert all the argument types
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\ctype.h(146): could be 'int tolower(int)'
1> while trying to match the argument list '(const char [6])'
Nov 14, 2014 at 9:47am UTC
Make sure your tolower function has been declared before you try to call it.
Nov 14, 2014 at 9:58am UTC
I forgot to include the parameters in the prototype -_-
Thank you for the help.