• Advertisement

Archived

This topic is now archived and is closed to further replies.

Passing char array to function

This topic is 5464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to write a simple trim function to remove spaces on the left/right of the string. I have most of the function done, however, I need to be able pass the string to the function and return the string afterwards. So, I came up with this:
void Trim(char **szString);
 
However, when I try to this, it won''t work:
char szTest[] = "    Test    Test     ";
Trim(&szTest);
 
When I make szTest a char *szTest it compiles fine. How should the function header look like, to pass both ways? Sand Hawk

Share this post


Link to post
Share on other sites
Advertisement
change void Trim(char **szString) to void Trim(char *szString)

and change Trim(&szTest) to Trim(szTest)


(when an array is passed as an argument, it functions like a pointer)

PS: excellent book "Pointers on C" (A. Kenneth Reek)

Share this post


Link to post
Share on other sites

  • Advertisement