Created
June 27, 2018 23:18
-
-
Save clementi/6bb207fe2bb235b05d0efe7c62a808c9 to your computer and use it in GitHub Desktop.
List the contents of the PATH environment variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(void) { | |
char* path = getenv("PATH"); | |
#ifdef _WIN32 | |
char* sep = ";"; | |
#else | |
char* sep = ":"; | |
#endif | |
char *pathItem; | |
pathItem = strtok(path, sep); | |
while (pathItem != NULL) { | |
printf("%s\n", pathItem); | |
pathItem = strtok(NULL, sep); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment