从完整路径下使用MSVS2005提取文件名 [英] Extract file name from full path in C using MSVS2005

查看:133
本文介绍了从完整路径下使用MSVS2005提取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C程序中,我有一个字符串(文件路径明确,这是保存在 ARGV的 exe文件名称[0] )。我想提取文件名,并使用微软的Visual Studio 2005中的任何内置的功能是什么?弃的目录路径

In a C program, I have a file path in a string (specifically, this is the exe name stored in argv[0]). I would like to extract the file name and discard the directory path using MS Visual Studio 2005. Any built in function for that?

推荐答案

有关参考,这里的code我实现了,按说赢/ Unix的兼容:

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 == '/'))
        {
            pfile++;
            break;
        }
    }

这篇关于从完整路径下使用MSVS2005提取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆