Obtain the Linux C language environment variable ENV/getenv, and obtain the C language usage method!
# Include <stdio. h> Int main (INT argc, char ** argv, char ** env) { Extern environ; Printf ("environ = % P \ n", Environ ); Printf ("Env = % P \ n", ENV );
}
|
# Include <stdio. h> # Include <string. h> Int main () { Extern char ** environ; Printf ("environ = % P \ n", Environ ); Char ** Env = environ; While (* env! = NULL ){ Printf ("% s \ n", * env ++ ); } /* Want To Know The Lang environment variable value */ Char * value = NULL; // This variable stores the value ENV = environ; While (* env! = NULL ){ Char * STR = * env ++; If (strncmp (STR, "Lang", strlen ("Lang") = 0) {// lang = zh_cn Value = STR + strlen ("Lang") + 1; Break; } } Printf ("lang = % s \ n", value ); } |
# Include <stdio. h> # Include <stdlib. h> Int main () { Char * value = getenv ("Lang "); Printf ("value = % s \ n", value ); Putenv ("Var = ABC"); // Add an environment variable Putenv ("lang = C"); // modify the environment variable Printf ("Var = % s \ n", getenv ("Var ")); Printf ("lang = % s \ n", getenv ("Lang ")); /* If the 3rd parameters are non-zero, replace them if the Lang environment variable already exists. If it is zero, if the environment variable already exists, do not replace */ Setenv ("Lang", "C", 1 );
} |