创建和访问环境变量 AOE3 STUDIO
赵湘宁
edu4u.com.cn
中国教育网
PATH=C:\WINDOWS AOE3 STUDIO
SET VERSION=1.1.3 www.edu-cn.com
VERSION=1.1.3 中国教程网
中国教程网
char * getenv(const char * name); 中国论文网
#include <stdlib.h>#include <stdio.h>int main(){ char * descr = getenv("PATH"); if (descr) printf("value of PATH is: %s", descr); else printf("variable not defined");} 中国教程网
int putenv(const char * var); 中国论文网
中国论文网
int stat = putenv("TEMP=C:\\TEMP");if (!stat){ printf("环境变量定义失败"); } www.edu4u.com.cn
void func(); #include <stdlib.h>#include <stdio.h>int main(){ bool debug=false; if (getenv("DBG")) debug=true; if (debug) printf("calling func"); func(); if (debug) printf("returned from func");} www.edu-cn.com
www.edu-cn.com