1. 字符串拼接
#define VERSION_DESC(name, author, date, extra) #name"_"#author"_v"#date"_"#extra
2. 去除目录文件前面的目录
#include <stdio.h> #include <string.h> #define DIR_FILE "/tmp/xxx/test" int main() { char *file; if(strrchr(DIR_FILE, '/')) file = strrchr(DIR_FILE, '/') + 1; printf("dir_file-> file [%s]\n", file); if(strrchr(file, '/')) file = strrchr(DIR_FILE, '/') + 1; printf("file-> file [%s]\n", file); return 0; }
运行结果
dir_file-> file [test] file-> file [test]