>How can I return an array of characters from a function?
You can't. Either return a pointer, or wrap the array in an object so that it can be copied as a single entity.
>I'm probably doing it wrong
Yes. Yes you are.
int get_size(char text[MAX_SIZE])
{
for (int i=0;i<MAX_SIZE;i++)
{
if (!(text[i]))
return i;
}
return MAX_SIZE;
} That's just funky. After the loop, i will be MAX_SIZE anyway, so why confuse readers more than you have to?
int get_size ( char text[] )
{
int i = 0;
while ( i < MAX_SIZE && text[i] != '\0' )
++i;
return i;
} Of course, even better would be taking the max size as an argument rather than hard coding some arbitrary macro that destroys reusability.
Tell me, what's wrong with the following code:
char* replace(...)
{
char new_text[MAX_SIZE];
...
return new_text;
} Too subtle? You're returning a pointer to local data. new_text is destroyed when replace returns, so your pointer to it refers to indeterminate data. This is undefined behavior. You must either dynamically allocate your memory, use an object that has an appropriate copy constructor, pass the array as an argument, or declare the array as static and suffer the pitfalls of that particular option.
>cin.sync();
That's not guaranteed to do what you think.
By the way, you're commenting the wrong parts of your code. Anything that isn't immediately obvious should have a comment, or be changed so that it's immediately obvious. The one thing I wondered while reading your code is precisely the comments you should have added: why are you reinventing the wheel when the standard library supports a huge portion of what you're trying to do?