请输入您要查询的百科知识:

 

词条 putenv
释义

函数名: putenv

头文件: #include<stdlib.h>

功 能: 把字符串加到当前环境中

用 法: int putenv(char *envvar);

函数说明: putenv()用来改变或增加环境变量的内容。参数enwar的格式为enwar=value,如果该环境变量原先存在,则变量内容会依参数enwar改变,否则此参数内容会成为新的环境变量

返回值: 执行成功则返回0,有错误发生则返回-1

错误代码: ENOMEM 内存不足,无法配置新的环境变量空间

注意:设置的环境仅对程序本身有效。你在程序里做的改变不会反映到外部环境中,这是因为变量的值不会从子进程传播到父进程,这样做更安全。

程序例:

#include <stdio.h>

#include <stdlib.h>

#include <alloc.h>

#include <string.h>

#include <dos.h>

int main(void)

{

char *path, *ptr;

int i = 0;

/* get the current path environment */

ptr = getenv("PATH");

/* set up new path */

path = malloc(strlen(ptr)+15);

strcpy(path,"PATH=");

strcat(path,ptr);

strcat(path,";c:\\\\temp");

/* replace the current path and display current environment */

putenv(path);

while (environ)

printf("%s\",environ);

return 0;

}

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/3/17 5:03:01