Question #12514

How to correct the error? TQ

#include <iostream>
using namespace std;

void recursiveToLower(char str[])
{
if ( str[0] != '\0' ) {
str[0] = toupper( str[0] ); // do this char
recursiveToLower( str+1 ); // recursively do the remaining chars
}
}

int main()
{
char word[10] ;
cin >> word

cout << recursiveToLower(word);

system ("pause");
return 0;
}

Expert's answer

Here is corrected code:

#include <iostream>
using namespace std;
&
char* recursiveToLower(char str[])
{
& if ( str[0] != '\0' ) {
str[0] = toupper( str[0] );& // do this char
recursiveToLower( str+1 ); // recursively do the remaining chars
& }
& return &str[0];
}
&
int main()
{
char word[10] ;
cin >> word;

cout << recursiveToLower(word) <<"\n";
&
system ("pause");
return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS