w3resource logo
C Programming Exercises

C Exercises: Get the environment string

C Variable Type : Exercise-9 with Solution

Write a C program to get the environment string.

Sample Solution:

C Code:


int main ()
		char * PathPtr;
		PathPtr = getenv ("PATH");

		if (PathPtr!=NULL)
			printf ("\nThe set path is: %s\n\n",PathPtr);

		return 0;

Sample Output:

The set path is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 

C Programming Code Editor:

Improve this sample solution and post your code through Disqus