I’m stuck on Stage The type builtin: executable files #mg5
I’ve tried using dirent and unistd headers, but my code cant pass de second test “type cp”
Here are my logs:
[tester::#MG5] Running tests for Stage #MG5 (The type builtin: executable files)
remote: [tester::#MG5] Running ./your_program.sh
remote: [your-program] $
remote: [tester::#MG5] > type cat
remote: [your-program] cat is /bin/cat
remote: [tester::#MG5] ✓ Received expected response
remote: [your-program] $
remote: [tester::#MG5] > type cp
remote: [your-program] cp: not found
remote: [tester::#MG5] Expected: “cp is /bin/cp”
remote: [tester::#MG5] Received: “cp: not found”
remote: [your-program] $
remote: [tester::#MG5] Received output does not match expectation.
remote: [tester::#MG5] Test failed
include relevant logs here (please make sure to keep the backticks around this!)
And here's a snippet of my code:
```c
} else if (strcmp(command, "type") == 0) {
int command_exists = 0;
char* env = getenv("PATH");
char* dir = strtok(env, ":");
while (dir != NULL) {
char dirpath[1024] = "";
strcpy(dirpath, dir);
strcat(dirpath, "/");
strcat(dirpath, argument);
if (access(dirpath, R_OK) == 0) {
printf("%s is %s\n", argument, dirpath);
command_exists = 1;
}
dir = strtok(NULL, ":");
}
if (command_exists == 0) {
printf("%s: not found\n", argument);
}
}