This is the output of the following code, but I expect it to be correct paths.
What is wrong in the output of odd indexes such as pathsarray[1] = ls/ls ?
---/usr/lib/lightdm/lightdm/ls
---ls/ls
---/usr/local/bin/ls
---ls/ls
---/usr/bin/ls
---ls/ls
---/bin/ls
---ls/ls
char *pathsarray[MAXARGS];//path
char *path=getenv("PATH");
tokenizeEnvPaths(path);
int i;
for(i=0;i<MAXARGS;i++)
{
if(pathsarray[i] != NULL)
{
strcat(pathsarray[i],"/");
strcat(pathsarray[i],"ls");
fprintf(stderr,"---%s\n",pathsarray[i]);
}
}
Here’s an SSCCE (Short, Self-Contained, Correct Example).
Example output: