Archived

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

Sand_Hawk

Passing char array to function

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
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