Skip to content

Instantly share code, notes, and snippets.

@clementi
Created June 27, 2018 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clementi/6bb207fe2bb235b05d0efe7c62a808c9 to your computer and use it in GitHub Desktop.
Save clementi/6bb207fe2bb235b05d0efe7c62a808c9 to your computer and use it in GitHub Desktop.
List the contents of the PATH environment variable
#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