69,371
社区成员
发帖
与我相关
我的任务
分享
// 比较文件名后缀(扩展名)
int CompFileSuffix(const char* file1, const char* file2){
const* suffix1 = strrchr(file1, ',');
const* suffix2 = strrchr(file2, ',');
return strcmp(suffix1, suffix2);
}
// 比较文件名前缀(除扩展名)
int CompFilePrefix(const char* file1,const char* file2){
const char* suffix1 = strrchr(file1, ',');
const char* suffix2 = strrchr(file2, ',');
size_t len1, len2, comp_len;
int resu;
len1 = suffix1 - file1;
len2 = suffix2 - file2;
comp_len = MIN(len1, len2);
resu = strncmp(file1, file2, comp_len);
if(resu == 0)return suffix1 - suffix2;
return resu;
}
// 比较文件名
int CompFileName(const char* file1, const char* file2){
int resu;
resu = CompFileSuffix(file1, file2);
if(resu == 0)return CompFilePrefix(file1, file2);
return resu;
}
先实现了,再效率
just do it.