# Help about #MG5 stage

**URL:** <https://forum.codecrafters.io/t/help-about-mg5-stage/3541>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [December 19, 2024, 5:50am UTC](https://forum.codecrafters.io/t/help-about-mg5-stage/3541 "2024-12-19T05:50:35Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![D10f](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/d10f/32/3530_2.png) [@D10f](https://forum.codecrafters.io/u/D10f)\
**Post date:** [December 19, 2024, 10:33am UTC](https://forum.codecrafters.io/t/help-about-mg5-stage/3541/4 "2024-12-19T10:33:17Z")

</div>

I think this is very similar to what happened to me [here](https://forum.codecrafters.io/t/tests-wont-pass-on-mg5/3511/9).

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.

```diff
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);

```

---

_[View the full topic](https://forum.codecrafters.io/t/help-about-mg5-stage/3541)._
