Created
October 25, 2016 01:15
-
-
Save jrelo/ac2bf48486fb7af06097753df6680970 to your computer and use it in GitHub Desktop.
Test setenv and print environment variables from *envp[] arg in main() versus extern char** environ;
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> | |
extern char** environ; | |
int main(int argc, char *argv[], char *envp[]) | |
{ | |
int i; | |
setenv("TESTVAR", "watvalue123", 1); | |
printf("From char *envp[]:\n"); | |
printf("---------------------------\n"); | |
for (i = 0; envp[i] != NULL; i++) | |
{ | |
printf("%s\n", envp[i]); | |
} | |
/* | |
while (*envp){ | |
printf("%s\n", *envp++); | |
} | |
*/ | |
printf("\nFrom extern char** environ:\n"); | |
printf("---------------------------\n"); | |
for(i = 0; environ[i] != NULL; i++) | |
{ | |
printf("%s\n", environ[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment