1、getenv函数
头文件:#include<stdlib.h>
函数原型: char * getenv(const char* name);
函数说明:getenv()用来取得参数name环境变量的内容。
函数参数:name为环境变量的名称,如果该变量存在则会返回指向该内容的指针。环境变量的格式为name=value。
返回值:若环境变量存在,返回环境变量值的指针,否则返回NULL
例子:
1 #include <stdlib.h> 2 #include <stdio.h> 3 int main() 4 { 5 char* path = NULL; 6 if((path = getenv("USER"))) 7 printf("USER = %s\n", path); 8 9 return 0; 10 }