int main(int ac, char **av, char **env) { unsigned int i = 1; while(getenv("env[i]") != NULL) { printf("%s\n", env[i]); i++; } return 0; }
As discussed above, arrays start at index 0 and the loop condition is wrong ("env[i]" is a fixed string, also getenv() takes a name but env[i] is a name=value pair):
"env[i]"
getenv()
name
env[i]
name=value
#include <stdio.h> int main(int ac, char **av, char **env) { for(unsigned i = 0; env[i]; i++) { printf("%s\n", env[i]); } return 0; }
As discussed above, arrays start at index 0 and the loop condition is wrong (
"env[i]"is a fixed string, alsogetenv()takes anamebutenv[i]is aname=valuepair):