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?

Recommended Answers

All 2 Replies

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

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.