Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * [envlist.c]
- * The console output of a list of a system's environment variables, and the corresponding memory
- * addresses where they are stored.
- *
- * (c) Damion 'Phr0z3n.dev' Tapper, 2015.
- * Email: Phr0z3n.Dev@Gmail.com
- * Website: http://L337Stuff.Blogspot.com
- */
- #include <stdio.h>
- #include <stdlib.h>
- /**
- * main() is implemented with the 'envp' argument variable that will point to the system's environment
- * variables.
- */
- int main(int argc, char *argv[], char **envp)
- {
- int i; /* Primary increment. */
- int j; /* Secondary increment. */
- /**
- * Create a buffer that will store the name (only) of each environment variable, and allocate
- * space for it in memory at the same time:
- */
- char *envBuff = (char *)malloc(100);
- /**
- * Traverse the environment variables pointer array (until a null value is reached):
- */
- for(i = 0; envp[i] != '\0'; i++)
- {
- /**
- * Copy the name (only) of each environment variable into the buffer:
- */
- for(j = 0; envp[i][j] != '='; j++)
- envBuff[j] = envp[i][j];
- /**
- * Terminate the name of the environment variable with the null character:
- */
- envBuff[j] = '\0';
- /**
- * Print out the name of the environment variable, and the corresponding memory address
- * where it is located:
- */
- printf("%s is at %p\n", envBuff, getenv(envBuff));
- }
- /**
- * Delete the buffer from memory, being that it's done with:
- */
- free(envBuff);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement