#include <stdio.h>
#include <sys/types.h>
#include <string.h>
int trim_dots(const char * path)
{
char * pos = NULL;
pos = strrchr(path, '/');
printf("%s\n", pos);
if(pos == NULL)
{
perror("strrchr");
return -1;
}
if((strcmp(pos+1, ".") == 0) || (strcmp(pos+1, "..") == 0))
return 0;
else
return -2;
return 0;
}
int main(int argc, const char *argv[])
{
int ret = -1;
const char * path1 = "12340/.";
const char * path2 = "abcd/..";
ret = trim_dots(path1);
if(ret != 0)
{
fprintf(stderr, "trim_dots error %d\n", ret);
}
else
{
fprintf(stdout, "trim_dot ok!\n");
}
ret = trim_dots(path2);
if(ret != 0)
{
fprintf(stderr, "trim_dots error %d\n", ret);
}
else
{
fprintf(stdout, "trim_dots ok!\n");
}
return 0;
}
C中字符向右查找实现截取内容
最新推荐文章于 2022-12-31 20:43:17 发布