# (c++) cat exists in a different directory than expected

**URL:** https://forum.codecrafters.io/t/c-cat-exists-in-a-different-directory-than-expected/4632
**Category:** Challenges
**Tags:** challenge:shell
**Created:** [February 3, 2025, 3:24am UTC](https://forum.codecrafters.io/t/c-cat-exists-in-a-different-directory-than-expected/4632 "2025-02-03T03:24:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ImVis10](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/imvis10/32/4707_2.png) [@ImVis10](https://forum.codecrafters.io/u/ImVis10)
#### Post date: [February 3, 2025, 3:24am UTC](https://forum.codecrafters.io/t/c-cat-exists-in-a-different-directory-than-expected/4632/1 "2025-02-03T03:24:28Z")

</div>

I’m stuck on Stage #MG5.

cat utility exists under /bin and **not** in /usr/bin in my local.

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/a/aed2f1d964266ca1838b0c6e9f247cbd3a62bc97.png)

Here are my logs:

```auto
remote: [your-program] $ type cat
remote: [your-program] cat: not found
remote: [tester::#MG5] Output does not match expected value.
remote: [tester::#MG5] Expected: "cat is /usr/bin/cat"
remote: [tester::#MG5] Received: "cat: not found"
remote: [your-program] $ 
remote: [tester::#MG5] Assertion failed.
remote: [tester::#MG5] Test failed

```

```auto

```

And here’s a snippet of my code that returns the path of the file:

```auto
string get_path(string& file_name, string& path_env) {
  string dir, abs_path;
  stringstream ss(path_env);

  while (getline(ss, dir, ':')) {
    abs_path = dir + '/' + file_name;
    ifstream file(file_name);
    if (file.good()) return abs_path;
  }
  return "";
}

```

Thanks for helping out.

---

<div class="post-metadata">

### Author: ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)
#### Post date: [February 6, 2025, 10:25pm UTC](https://forum.codecrafters.io/t/c-cat-exists-in-a-different-directory-than-expected/4632/3 "2025-02-06T22:25:46Z")

</div>

Hi @ImVis10, the bug is here:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/f/fb60278368d1a945f77fd72c7df303400901b72f.png)

By the way, `cat` can be located at different paths on different systems. Let me know if you’d like further assistance!

---

<div class="post-metadata">

### Author: ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)
#### Post date: [March 10, 2025, 9:45am UTC](https://forum.codecrafters.io/t/c-cat-exists-in-a-different-directory-than-expected/4632/5 "2025-03-10T09:45:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)
#### Post date: [March 15, 2025, 9:46am UTC](https://forum.codecrafters.io/t/c-cat-exists-in-a-different-directory-than-expected/4632/6 "2025-03-15T09:46:17Z")

</div>

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