修改环境变量

Code:
  1. #include <stdlib.h>   
  2. #include <stdio.h>   
  3. #include <alloc.h>   
  4. #include <string.h>   
  5. #include <dos.h>   
  6. #include <conio.h>   
  7.   
  8. int main()   
  9. {   
  10.     char *path;   
  11.     char *ptr;   
  12.     int i;   
  13.     clrscr();   
  14.     puts("This program is to get the Path and change it.");   
  15.     //获取当前    
  16.     ptr = getenv("PATH");   
  17.        
  18.     //更新path   
  19.     path = (char*)malloc(strlen(ptr) + 20);   
  20.     strcpy(path, "PATH=");   
  21.     strcat(path, ptr);   
  22.     strcat(path, ";c://temp//hello");   
  23.        
  24.     //更新path并显示所有的环境变量   
  25.     putenv(path);   
  26.     while (environ[i])   
  27.     {   
  28.         printf(" >> %s/n", environ[i]);   
  29.         ++i;   
  30.     }   
  31.     printf(" Press any key to quit...");   
  32.     getch();   
  33.        
  34.     return 0;   
  35. }   

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值