I'm browsing directory paths. Currently I start at the users home directory:
char* dir;
dir = getenv("HOME"
dir = strcat(dir, "/"
Now 'dir' most likely equals something like this:
"/home/user/"
To go down into a directory is easy just...
dir = strcat(dir, "mydir/"
...add the directory name to the path and open it. My question is how can I remove "mydir/" when I want to go up? I know that you can just append "../" to the entire directory path and achieve the same results, but I don't want the char* dir to grow indefinitely as the program is in use. The problem is that this is more of a regular expression type thing not a hardcoded substring type thing. Is there a string.h function that can accomplish this or another efficient way to do it?
Thanks,
-bitwise
char* dir;
dir = getenv("HOME"
dir = strcat(dir, "/"
Now 'dir' most likely equals something like this:
"/home/user/"
To go down into a directory is easy just...
dir = strcat(dir, "mydir/"
...add the directory name to the path and open it. My question is how can I remove "mydir/" when I want to go up? I know that you can just append "../" to the entire directory path and achieve the same results, but I don't want the char* dir to grow indefinitely as the program is in use. The problem is that this is more of a regular expression type thing not a hardcoded substring type thing. Is there a string.h function that can accomplish this or another efficient way to do it?
Thanks,
-bitwise