C语言中获取文件名
char str[128] = "./A20221212172934U.avi";
char buf[128] = "";
sscanf(str, "%*[^/]/A%[^.]",buf);
printf("buf:%s\n",buf);
这样获取到的是20221212172934U
char str[128] = "./A20221212172934U.avi";
char buf[128] = "";
sscanf(str, "%*[^/]/%[^.]",buf);
printf("buf:%s\n",buf);
这样获取到的是A20221212172934U
获取字符串中的路径
char str[128] = "./A20221212172934U.avi";
char buf[128] = "";
int i = 0;
int start, end;
while(str[i] != '\0')
{
if(str[i] == '/')
start = i;
i++;
}
printf("start:%d\n",start);
printf("str:%s\n",str);
printf("buf:%s\n",buf);
strncpy(buf, str, start);
printf("buf:%s\n",buf);
最终获取出的路径为“.”