0

Hi,

I am trying to create a method that accepts a pointer to a (static) string so that it can modify the string. I have something similar to this:

void modifyString(char **pstr) {
    char *str = *pstr;
    // Make changes to str ...
}

void doSomething() {
    char str[] = "Hello World";
    modifyString(&str);
}

If I compile the above code, I get the following message:
warning: passing arg 1 of 'modifyString' from incompatible pointer type

How can I write a method which will allow me to modify the contents of a static string?

2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by Dark_Knight
0
void modifyString(char *pstr) {
    char *str = pstr;
    // Make changes to str ...
}

void doSomething() {
    char str[] = "Hello World";
    modifyString(str);
}
0

Thanks. I was trying to do what I would normally do with other types (e.g. int). But I now realize that since char* is already a pointer I didn't need to worry about the pass by reference/pass by value issue.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.