Lets say I have a function:
void split_path_file(char** p, char** f, char *pf) { //malloc and set *p to file path, malloc and set *f to file name //p
I came up with the following, of course this assumes that pf is malloced.
void split_path_file(char** p, char **f, char *pf) { char *posp = strrchr(pf, '\\'); *posp = '\0'; *p = strdup(pf); *f = strdup(posp+1); *posp = '\\'; }
Not sure if this is a better approach than above answers.