It has been a while since I messed with C/C++, and my memory of the available functions for working with a char* has gone out the window.
I currently use the following code to get the Current Working Directory…
char *path = NULL;
size_t size = 0;
path = _getcwd(path, size);
Msg("Current Working Directory: %s\n", path);
However, I need to take this path, then cut off the last directory, dropping it to the previous directory. It currently stores something like “C:/srcds/orangebox” in path, and I need to drop the last directory from this to get the correct path. In this case, it would be “C:/srcds”.
What is the best way to do this with a char*? Please don’t suggest to use strings. I know this is immensely easier, but the SDK I use revolves heavily around char* instead, so I try to stick with this for readability.
Okay – to keep your life complicated..
strrchrto find the last\memcpy(unless you havestrncpy) to copy number of characters to that point.I should add that 1. will return the last
\, so you if your path is likeC:/foo/bar/, it will stop at/– so you’ll have to do some boundary checks… I did say “to keep your life complicated”…