I keep getting conversion errors. What should I put as the return statement in the function definition?
Code:
#include <iostream>
using namespace std;
char capitalize(char []);
int main()
{
char string[81];
char c;
cout << "Enter a sentence" << endl;
cin.getline(string, 81);
c = capitalize(string);
cout << endl << c << endl;
return 0;
}
char capitalize(char string[])
{
register int i = 0;
while (string[i++])
{
string[0] = toupper(string[0]);
if (string[i] == ' ')
string[i + 1] = toupper(string[i + 1]);
}
return string;
}
This is the only solution I can come up with, but I want the cout statement that displays the string to be in main() instead of the function definition of capitalize().
Code:
#include <iostream>
using namespace std;
void capitalize(char []);
int main()
{
char string[81];
cout << "Enter a sentence" << endl;
cin.getline(string, 81);
capitalize(string);
return 0;
}
void capitalize(char string[])
{
register int i = 0;
while (string[i++])
{
string[0] = toupper(string[0]);
if (string[i] == ' ')
string[i + 1] = toupper(string[i + 1]);
}
cout << endl << string << endl;
}