Below there's a function that given a string of the form "../data/afile.txt" separates the path("../data/") from the file name("afile.txt"). I can get the path succesfully, but unfortunately I can't get the file name correctly.
Code:
void SplitStringToFileAndPath(char **file, char **path, const char *string)
{
int len = strlen(string);
int index = 0, j = 0;
// search the string from the end to beggining to find the last '/' or '\' character
for(int i = len; string[i] != '/' && string[i] != '\\'; i--)
j++;
// find the position from the beginning of the last '/' or '\'
index = len - j + 1;
// extract path
//delete *path;
*path = new char[index + 1];
// copy path
for(int i = 0; i < index; i++)
(*path)[i] = string[i];
(*path)[index] = '\0';
// extract filename
//delete *file;
*file = new char[len - index + 1];
for(int i = 0; i < (len - index); i++)
(*file)[i] = string[(len - index) + i];
(*file)[len - index] = '\0';
}