[C] 把字符串加到当前环境中 →→→→→进入此内容的聊天室

来自 , 2020-10-30, 写在 C, 查看 105 次.
URL http://www.code666.cn/view/0233f3bb
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <alloc.h>
  4. #include <string.h>
  5. #include <dos.h>
  6.  
  7. int main(void)
  8. {
  9.    char *path, *ptr;
  10.    int i = 0;
  11.  
  12.    /* get the current path environment */
  13.    ptr = getenv("PATH");
  14.  
  15.    /* set up new path */
  16.    path = malloc(strlen(ptr)+15);
  17.    strcpy(path,"PATH=");
  18.    strcat(path,ptr);
  19.    strcat(path,";c:\\temp");
  20.  
  21.    /* replace the current path and display current environment */
  22.    putenv(path);
  23.    while (environ[i])
  24.        printf("%s\n",environ[i++]);
  25.  
  26.    return 0;
  27. }
  28.  

回复 "把字符串加到当前环境中"

这儿你可以回复上面这条便签

captcha