Help about #MG5 stage

I could fix this, closed

Hi @diego-dev018, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

I think this is very similar to what happened to me here.

The call to strtok is destructive, meaning that it modifies the string it acts upon in place. If you run your code in your local machine and try to run type ls for example, it will work once but if you run the same again it will fail. That’s because it’s chopping the PATH string constantly.

You’d have to run strndup to duplicate it first, and use that.

char *pathenv = getenv("PATH");
+ char *pathdup = strndup(pathenv, strlen(pathenv));
char *delimit = ":";
char *token;
DIR *dir;
struct dirent *dp;
- token = strtok(pathenv, delimit);
+ token = strtok(pathdup, delimit);

That’s a different issue. You can see from the thread that I created that there’s a /bin folder in the path:

In my case, the test is expecting to find cp inside /bin but, as per the order of the directories in the path variable, it find it sooner inside /usr/bin which is what is causing my tests to fail.

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.