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
Maybe a bit late to the party, but the best solution I have found and have been using for years is the two functions dirname
and basename
path dirname basename
"/usr/lib" "/usr" "lib"
"/usr/" "/" "usr"
"usr" "." "usr"
"/" "/" "/"
They are great for separating parts of a path/filename. Together with realpath() they are IMHO unbeatable in simplicity and power.
http://linux.die.net/man/3/basename
http://man7.org/linux/man-pages/man3/realpath.3.html