Modifying string inside a method

Hi,
I want to change the string inside a method. I wrote following code but it won't do it.
1
2
3
4
5
6
7
8
9
10
11
12
void change_string(const char * the_string)
 {
    cout << the_string << endl;
    the_string = another_string();
 }

int main()
{
const char *pzMyStr = "Hello";
change_string(pzMyStr);
cout << pzMyStr << endl;
}


Hello
Hello


I want that second output to be Another string. I want to do it without string objects.
Last edited on
Do you know what constant means? And do you know what a char* and a char array are?
Yes I know what const char * means. it means I can change the char to which the_string points, but I cannot modify the char at which it points.
And you want to modify the string, not the pointer. That's why passing a const char* is meaningless.
I don't want to modify it. I want to allocate new location for that char pointer. Having const will not restrict that.
Topic archived. No new replies allowed.