# \[C\]\[Stage #IP1\] local testing works but codecrafters test fails?

**URL:** <https://forum.codecrafters.io/t/c-stage-ip1-local-testing-works-but-codecrafters-test-fails/6788>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [March 15, 2025, 8:57am UTC](https://forum.codecrafters.io/t/c-stage-ip1-local-testing-works-but-codecrafters-test-fails/6788 "2025-03-15T08:57:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![21mcme04](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/21mcme04/32/6039_2.png) [@21mcme04](https://forum.codecrafters.io/u/21mcme04)\
**Post date:** [March 15, 2025, 8:57am UTC](https://forum.codecrafters.io/t/c-stage-ip1-local-testing-works-but-codecrafters-test-fails/6788/1 "2025-03-15T08:57:44Z")

</div>

I’m stuck on Stage #IP1.

I’ve tried running the program locally with the path to my local program to print the agruments and their count, it prints correctly, even in the code crafters cli i get the correct output for everything except for the line

```auto
Program was passed X args (including program name).

```

here i am getting X to be more than X but in logs i am getting upto exactly X-1(including 0).

Here are my logs:

```auto
[tester::#IP1] Running tests for Stage #IP1 (Run a program)

[tester::#IP1] [setup] export PATH=/tmp/baz:$PATH

[tester::#IP1] [setup] Available executables:

[tester::#IP1] [setup] - custom_exe_8647

[tester::#IP1] Running ./your_program.sh

[your-program] $ custom_exe_8647 Emily

[your-program] Program was passed 3 args (including program name).

[tester::#IP1] Output does not match expected value.

[tester::#IP1] Expected: "Program was passed 2 args (including program name)."

[tester::#IP1] Received: "Program was passed 3 args (including program name)."

[your-program] Arg #0 (program name): custom_exe_8647

[your-program] Arg #1: Emily

[your-program] Program Signature: 4964934947

[your-program] $

[tester::#IP1] Assertion failed.

[tester::#IP1] Test failed

```

And here’s a snippet of my code:

```C
void executablesInPath(char* input) {
    char* duplicateInput = strdup(input);
    char* path = getenv("PATH");
    if(!duplicateInput) {
        perror("strdup in executablesInPath");
        return;
    }
    char* command = strtok(duplicateInput, " ");
    char* commandPath = findCommandInPath(command, path);
    if(commandPath != NULL) {
        if(!duplicateInput) {
            perror("strdup in executablesInPath");
            return;
        }
        char* argumentArray[100];
        int argumentCount = 0;
        char* argument = strtok(input, " ");
        while(argument != NULL) {
            if(!isspace(argument[0])){
                argumentArray[argumentCount] = argument;
                argumentCount++;
            }
            argument = strtok(NULL, " ");
        }
        pid_t pid = fork();
        if(pid == 0) {
            execv(commandPath, argumentArray);
            perror("execv in executablesInPath");
        } else if(pid < 0) {
            perror("fork in executablesInPath");
        } else {
            wait(NULL);
        }
        free(duplicateInput);
    }
    return;
}

```

---

<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 15, 2025, 10:08am UTC](https://forum.codecrafters.io/t/c-stage-ip1-local-testing-works-but-codecrafters-test-fails/6788/4 "2025-03-15T10:08:37Z")

</div>

@21mcme04, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<div class="post-metadata">

**Author:** ![21mcme04](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/21mcme04/32/6039_2.png) [@21mcme04](https://forum.codecrafters.io/u/21mcme04)\
**Post date:** [March 15, 2025, 10:25am UTC](https://forum.codecrafters.io/t/c-stage-ip1-local-testing-works-but-codecrafters-test-fails/6788/5 "2025-03-15T10:25:18Z")

</div>

@andy1li [GitHub - 21mcme04/codecrafters-shell-c](https://github.com/21mcme04/codecrafters-shell-c.git) here is the github repo link.

---

<div class="post-metadata">

**Author:** ![21mcme04](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/21mcme04/32/6039_2.png) [@21mcme04](https://forum.codecrafters.io/u/21mcme04)\
**Post date:** [March 18, 2025, 7:05am UTC](https://forum.codecrafters.io/t/c-stage-ip1-local-testing-works-but-codecrafters-test-fails/6788/6 "2025-03-18T07:05:18Z")

</div>

There was a small issue with the code, fixed it(added NULL termination for exec). Now it is working.

---

<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 23, 2025, 7:07am UTC](https://forum.codecrafters.io/t/c-stage-ip1-local-testing-works-but-codecrafters-test-fails/6788/8 "2025-03-23T07:07:09Z")

</div>

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