我已经尝试了一段时间,现在我完全不知道如何解决这个问题。我有一个相当不错的规模项目,并且我无数次使用strtok而没有任何问题,但是在这里不起作用。请帮助:(
编辑:我正在寻找前缀删除而不是strtok。如果有人感到困惑并用谷歌搜索,我将把它留在这里。
这是有问题的代码
#include <stdio.h>
#include <string.h>
int main()
{
char root[1000];
char home[1000];
strcpy(root,"/Users/me/Desktop/my-project"); // this is working
strcpy(home,"/Users/me/Desktop/my-project/home"); // this is working
strtok(home,root); // here's the problem
printf("%s",home);
}
结果1:
/Users/me/Desktop/my-project/h
我也尝试过:
char *ptr = strtok(home,root);
printf("%s",ptr);
结果2:
h
都不应该都返回/home
吗?