Jump to content
  • Advertisement


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


Passing char array to function

This topic is 5586 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     ";
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
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

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!