变量的值。
这里有一个小技巧。当运行 Windows 时,Windows 设置了一个名为
WINDIR 的新的环境变量,它包含了 Windows 目录的路径全名。下面这段简
单的程序用来检索这个串:
# include <stdlib. h>
main(int argc, char * * argv)
{
char envValue[l29];
char * envPtr = envValue ;
envPtr = getenv("windir");
/ * print the Windows directory * /
printf("The Windows Directory is %s\n" , envPtr);
}
这个程序还可以用来判断当前是否正在运行 Windows,以及 DOS 程序是
否运行在一个 DOS shell
“
下,而不是运行在 真正的"DOS 下。注意,程序中的
windir
——
字符串是小写
这一点很重要,因为它对大小写是敏感的。如果你使
用 WINDIR,getenv()就会返回一个 NULL 串(表示变量未找到错误)。
用一 putenv()函数也可以设置环境变量。但要注意,该函数不是一个
ANSI 标准函数,在某些编译程序中它可能不以这个名字出现,或者根本就不
存在。你可以用一 putenv()函数做许多事情。实际上,在上面那个例子中 ,
Windows 正是用这个函数创建了 windir 环境变量。
请参:
14.2 怎样在程序中调用 DOS 函数?
14.3 怎样在程序中调用 BIOS 函数?
14.2 怎样在程序中调用 DOS 函数?
其实,当调用 printf(),fopen(),fclose(),名字以一 dos 开始的函数以