所以我开始拆分环境路径,我把它们都搞定了
char *token;
char *path;
char copy[200];
char *search = ":";
char echo[] = "echo";
int main(){
path= getenv("PATH");
strncpy(copy,path,sizeof(copy)-1);
token = strtok (copy,":");
printf("%s\n",path);
while(token != NULL)
{
printf("%s\n",token);
token= strtok (NULL,":");
}
}
我想要我需要
/usr/lib64/qt-3.3/bin
/usr/NX/bin
/usr/local/bin
/usr/bin
/usr/divms/bin
/usr/local/sbin
/usr/sbin
/space/befox/bin
/space/befox/bin
现在我只需要在所有这些的末尾加上一个“/”,我让它工作但它只打印第一个。所以这是我的代码:
char *token;
char *path;
char copy[200];
char *search = ":";
char echo[] = "echo";
char *result;
int main(){
path= getenv("PATH");
strncpy(copy,path,sizeof(copy)-1);
token = strtok (copy,":");
printf("%s\n",path);
while(token != NULL)
{
result = strncat (token,"/",sizeof(token+1));
printf("%s\n",token);
token= strtok (NULL,":");
}
}
现在我得到:
/usr/lib64/qt-3.3/bin/
我需要解决什么问题才能得到所有末尾带有“/”的行?