获取文件扩展名C
回答
const char *get_filename_ext(const char *filename) {
const char *dot = strrchr(filename, '.');
if(!dot || dot == filename) return "";
return dot + 1;
}
printf("%s\n", get_filename_ext("test.tiff"));
printf("%s\n", get_filename_ext("test.blah.tiff"));
printf("%s\n", get_filename_ext("test."));
printf("%s\n", get_filename_ext("test"));
printf("%s\n", get_filename_ext("..."));
'dot = strrchr(filename,'。');','dot!= NULL'后暗示'* dot =='。''因此您的测试应该简单'如果(点)'。 – 2011-03-15 09:07:00
我收到一个错误:'renamer.c:11:警告:不兼容隐式声明的内置函数'strrchr'' – errorhandler 2011-03-15 09:08:57
'#include
您可以使用strrchr
函数搜索字符串中最后一次出现的字符,以找到最终的点。从那里,你可以读取字符串的其余部分作为扩展名。
查找与strrchr
最后的点,然后提前1焦炭
#include <stdio.h> /* printf */
#include <string.h> /* strrchr */
ext = strrchr(filename, '.');
if (!ext) {
/* no extension */
} else {
printf("extension is %s\n", ext + 1);
}
没有必要复制它 - 您将返回一部分以原始字符串结尾的字符串,因此不需要进行任何修改。 – ThiefMaster 2011-03-15 09:11:14
复制删除,谢谢 – pmg 2011-03-15 09:13:30
- 1. Objective-C:获取文件类型支持的文件扩展名
- 2. 使用preg_replace获取文件扩展名
- 3. 获取文件的扩展名(编辑)
- 4. 获取文件扩展名 - jquery
- 5. asp.net mvc HttpPostedFileBase获取文件扩展名
- 6. Angularjs如何获取文件扩展名?
- 7. Smarty获取文件扩展名
- 8. PHP,获取文件名没有扩展
- 9. 从文件扩展名获取ImageFormat
- 10. Primefaces FileUpload获取文件扩展名
- 11. FileUpload获取文件扩展名
- 12. C#获取所有没有目录扩展名的文件名
- 13. 如何在C#Windows中获取文件大小,文件名,文件扩展名?
- 14. 用Python获取文件名和扩展名为hdfs的文件
- 15. 从URL和带文件扩展名获取文件名
- 16. 从文件获取扩展
- 17. 分段错误尝试获取文件的扩展名用C
- 18. 获取不带扩展名的文件类型c#
- 19. 从文件名中获取文件名和扩展名没有文件名
- 20. 获取文件的扩展名,但不在路径中提供扩展名
- 21. 通过文件扩展名获取扩展名和图标的最快方法?
- 22. 提取文件名(不含扩展名)
- 23. powershell - 提取文件名和扩展名
- 24. 文件扩展名
- 25. 文件扩展名
- 26. 当文件没有扩展名时如何获取文件UTI?
- 27. Python:获取包含特定文件扩展名的文件夹
- 28. 获取由OpenFileDialog选择的文件的文件扩展名
- 29. php:从损坏的文件中获取文件扩展名
- 30. 从wget响应中获取“文件名”和扩展名
[C语言入门文件扩展名]的可能的复制(http://stackoverflow.com/questions/3035225/getting-文件扩展名为c语言) – nibot 2017-03-04 18:15:30