C语言 Linux环境变量

/*
*@author cody
*@date 2014-08-12
*@description 
*/

/*
extern char **environ  //environment values

#include <stdlib.h>
char *getenv(const char *name);
int setenv(const char *name,const char *value,int rewrite); // set enviroment if exists rewrite - 0 do  not rewrite not 0 rewrite
void unsetenv(const char *name); //delete env by name
*/

#include <stdio.h>
#include <stdlib.h>

void environment(){
    extern char **environ;
    int i;
    for(i = 0;environ[i] != NULL;i ++){
        printf("%s\n",environ[i] );
    }
}

void getPath(){

    char *path = getenv("PATH");
    printf("PATH = %s\n",path );

    setenv("PATH","HELLO",1);
    path = getenv("PATH");
    printf("PATH = %s\n",path );


}

int main(int argc, char const *argv[])
{
    
    //environment();
    getPath();
    return 0;
}

 

posted @ 2014-08-12 14:39  誑逩の蝸犇  阅读(999)  评论(0编辑  收藏  举报