Monday, 7 November 2011

How do you view the PATH? in C programming

How do you view the PATH?

Your C compiler library contains a function called getenv() that can retrieve any specified environment
variable. It has one argument, which is a pointer to a string containing the environment variable you want
to retrieve. It returns a pointer to the desired environment string on successful completion. If the function
cannot find your environment variable, it returns NULL.
The following example program shows how to obtain the PATH environment variable and print it on-screen:
#include <stdio.h>
#include <stdlib.h>
void main(void);
void main(void)
{
char* env_string;
env_string = getenv(“PATH”);
if (env_string == (char*) NULL)
printf(“\nYou have no PATH!\n”);
else
printf(“\nYour PATH is: %s\n”, env_string);
}

Cross Reference:

None.

No comments:

Post a Comment