User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 423,540 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,195 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 999 | Replies: 2 | Solved
Reply
Join Date: Jan 2008
Posts: 8
Reputation: Dark_Knight is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Dark_Knight's Avatar
Dark_Knight Dark_Knight is offline Offline
Newbie Poster

Incompatible pointer type problem

  #1  
Jan 13th, 2008
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?
Last edited by Dark_Knight : Jan 13th, 2008 at 8:25 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Posts: 1,404
Reputation: Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all 
Rep Power: 10
Solved Threads: 95
Aia's Avatar
Aia Aia is offline Offline
Nearly a Posting Virtuoso

Re: Incompatible pointer type problem

  #2  
Jan 13th, 2008
  1. void modifyString(char *pstr) {
  2. char *str = pstr;
  3. // Make changes to str ...
  4. }
  5.  
  6. void doSomething() {
  7. char str[] = "Hello World";
  8. modifyString(str);
  9. }
"No man's life, liberty, or property is safe while the legislature is in session." ~ Mark Twain
Reply With Quote  
Join Date: Jan 2008
Posts: 8
Reputation: Dark_Knight is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Dark_Knight's Avatar
Dark_Knight Dark_Knight is offline Offline
Newbie Poster

Re: Incompatible pointer type problem

  #3  
Jan 13th, 2008
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.
Live life on the edge ... you take up less room that way.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 5:41 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC