I have a C program that prints every environmental variable, whose name is given by stdin. It prints variables such as $PATH, $USER but it doesn't see the environmental variables i define myself in the Linux shell... For instance, in bash I define my=4, and I expect the program to return 4 when I give the input "my".
int main () {
char * key = (char * )malloc(30);
scanf("%s", key);
if(getenv(key) != NULL)
printf("%s\n", getenv(key));
else
printf("NULL\n");
return 0;
}
What can I do in order to improve the results of getenv? I want it to show me all the environmental variables with all the inheritances from the Linux shell . Thank you..