Well it can get kind of hairy if you're expecting whatever tokens you find to be files. fopen() doesn't cope with directories. Just try it yourself and see.
But, just to illustrate...
Code:
#include <stdio.h>
#include <string.h>
int main( void )
{
char dir[] = "a/sample/directory";
char file[] = "a/sample/file.txt";
char *token;
if ( (token = strrchr( dir, '/' )) != NULL )
{
printf( "filepath=%s, *token=%c, token=%s\n", dir, *token, token );
}
if ( (token = strrchr( file, '/' )) != NULL )
{
printf( "filepath=%s, *token=%c, token=%s\n", file, *token, token );
}
return 0;
}
See how it can appear to be correct?