Skip to content

Instantly share code, notes, and snippets.

@gomasy
Last active October 16, 2015 05:46
Show Gist options
  • Save gomasy/fd9721b9884b762ac541 to your computer and use it in GitHub Desktop.
Save gomasy/fd9721b9884b762ac541 to your computer and use it in GitHub Desktop.
get environment variable
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
char *ptr;
if (argc < 3) {
printf("Usage: %s [environment] [path]\n", argv[0]);
return 0;
}
ptr = getenv(argv[1]);
ptr += (strlen(argv[0]) - strlen(argv[2])) * 2;
printf("%s : %p\n", argv[1], ptr);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment