- #include <stdlib.h>
- #include <stdio.h>
- #include <alloc.h>
- #include <string.h>
- #include <dos.h>
- #include <conio.h>
- int main()
- {
- char *path;
- char *ptr;
- int i;
- clrscr();
- puts("This program is to get the Path and change it.");
- //获取当前
- ptr = getenv("PATH");
- //更新path
- path = (char*)malloc(strlen(ptr) + 20);
- strcpy(path, "PATH=");
- strcat(path, ptr);
- strcat(path, ";c://temp//hello");
- //更新path并显示所有的环境变量
- putenv(path);
- while (environ[i])
- {
- printf(" >> %s/n", environ[i]);
- ++i;
- }
- printf(" Press any key to quit...");
- getch();
- return 0;
- }