获取路径中文件名的 C 语言代码如下:
#include <stdio.h> #include <string.h> const char *getFileName(const char *filePath) { const char *fileName = strrchr(filePath, '/'); if (fileName) { return fileName + 1; // 跳过 '/' 字符 } return filePath; } int main() { const char *file_path = "/路径/到/你的/文件.txt"; const char *file_name = getFileName(file_path); printf("文件名:%s\\n", file_name); 聚宝盆免费资料大全 return 0; }
在这个示例中, 澳门一肖一码必中一肖精华区函数会在文件路径中查找最后一个 '/' 字符,然后返回该字符后面的部分作为文件名。如果文件路径中没有 '/' 字符,它会返回整个路径作为文件名。运行代码后,它将输出文件的名称部分。
- 本文固定链接: https://huaxiatt.com/post/7588.html
- 转载请注明: admin 于 红色航投 发表