Skip to content

Instantly share code, notes, and snippets.

@Ayrx

Ayrx/getenvaddr.c

Created Aug 28, 2013
Embed
What would you like to do?
A simple piece of C code to print out the memory address of a specific environmental variable.
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
char *addr;
if (argc < 2) {
printf("Usage:\n%s <environment variable name>\n", argv[0]);
exit(0);
}
addr = getenv(argv[1]);
if (addr == NULL)
printf("The environment variable %s doesn't exist.\n", argv[1]);
else
printf("%s is located at %p\n", argv[1], addr);
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment