How to do getenv for a value stored in a char* string variable

53 Views Asked by At

a char * var = "EnvVariable"; this EnvVariable is stored in env variable example (EnvVariable="test")

now we want to get the value of EnvVariable in char *result .

when print result it will give me output of EnvVariable i.e test.

1

There are 1 best solutions below

0
Halfa On

I think you are looking for this exemple :

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

int main() {

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

    return 0;
}