ysap ysap - 10 months ago 41
C Question

Extract file name from full path in C using MSVS2005

In a C program, I have a file path in a string (specifically, this is the

name stored in
). I would like to extract the file name and discard the directory path using MS Visual Studio 2005. Any built in function for that?

Answer Source

For reference, here's the code I implemented, supposedly Win/Unix compatible:

    char *pfile;
    pfile = argv[0] + strlen(argv[0]);
    for (; pfile > argv[0]; pfile--)
        if ((*pfile == '\\') || (*pfile == '/'))