I am trying to write a complicated function as part of a file system program I am writing.(Well, complicated for me anyway). Because a user can specify a filename as either a relative path or an absolute path, it was recommended that I always use filenames as absolute paths, hence I am trying to write a build_absolute path function.
For example, if someone writes "myfile.txt", I need to locate all of the parent directories up to the root, and store the absolute path name in a string. So the absolute path would then be stored like:
/parent/parent/myfile.txt
My professor recommended using realloc to increase the size of the name array, and I think I understand that. My problem is as I go up the directory tree and get the names of the parents, how do I add them to the front of the array? strcat woul add it to the end, is there a function that will basically concatenate the new string to the front of the old one? Or is there a good way to go about this?
I understand everything about the assignment except this one part, and this is keeping me from going forward. If anyone could give me some advice, I would greatly appreciate it.
For example, if someone writes "myfile.txt", I need to locate all of the parent directories up to the root, and store the absolute path name in a string. So the absolute path would then be stored like:
/parent/parent/myfile.txt
My professor recommended using realloc to increase the size of the name array, and I think I understand that. My problem is as I go up the directory tree and get the names of the parents, how do I add them to the front of the array? strcat woul add it to the end, is there a function that will basically concatenate the new string to the front of the old one? Or is there a good way to go about this?
I understand everything about the assignment except this one part, and this is keeping me from going forward. If anyone could give me some advice, I would greatly appreciate it.
windows\system32\file.txt