Converting full path to file name in C

Hello,
I'm usually a c++ programmer but my teacher is forcing me to use regular old c.
I've been spending a lot of time figuring out how to manipulate strings. For instance the strncmp, strncat, and strcpy functions.

My question:
Is there a clean way to convert dir/dir/dir/filename.ext to filename.ext.

I can think of at least one way to do this: iterating backwards and keeping count of how many chars the filename has. Then iterating over just that section and copying each char one by one. This seems like a brute force method to me and I was hoping someone could point me to a better way of doing this.

Thank you in advance!
1
2
#include <libgen.h>
char* basename(char *path);

or `strrchr()', you may just point there (no need to copy)
Topic archived. No new replies allowed.