Skip to content

Instantly share code, notes, and snippets.

@jrelo
Created October 25, 2016 01:15
Show Gist options
  • Save jrelo/ac2bf48486fb7af06097753df6680970 to your computer and use it in GitHub Desktop.
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;
#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