How to print the environment variables in a C program using environ
.
extern char **environ
#include <unistd.h>
#include <stdio.h>
extern char **environ;
//...
int i = 0;
while(environ[i]) {
printf("%s\n", environ[i++]); // prints in form of "variable=value"
}
Do you mean
int main(int argc, char **argv, char **envp)
{
while(*envp!=null) {
printf("%s\n", *envp);
envp++;
}
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With