#include<stdio.h>
#include<malloc.h>
#include<string.h>
int main(){
char* path = "lost+found/d1/dentry";
char* str = malloc(100);
char *temp;
if(NULL == str) perror("malloc failed");
temp = str;
while(*path != '/'){
*str++ = *path++;
}
*str = '\0';
str = temp;
printf("\n str : %s \n",str);
return 0;
}
O / P:
str : lost+found
是否有任何库函数只能提取带分隔符的字符串“/”[strrchr和srchr给出'/'的最后和第一次出现,但是我搜索的字符串丢失+找到了。