You can find the length of the string and work backwards to find the file extension.
Now I am not sure if this is a project or what exactly this is for, but if you all you want is dependencies for
source files. Like all the headers a c or c++ file uses, there are already things you can do for that.
Two examples would be.
gcc -M sourcefile.c This will give you all the header files sourcefile.c needs to compile.
makedepend also can do this, but its been a while since I have done this.
Now I am not sure if this is why you are writing this program. Or if you are just writing it for
practice. However your task isn't a easy one. Cause if file one includes file two that includes file three,
then you have multiple layers of dependency, not to mention if file one, includes file two and file three, who both
include file four, you don't want two file fours in the dependency list for file one.