C Exercises: Get the environment string
Write a C program to get the environment string.
Sample Solution:
C Code:
#include<stdio.h> // Include the standard input/output header file.
#include<stdlib.h> // Include the standard library header file.
int main () // Start of the main function.
{
char * PathPtr; // Declare a pointer to char 'PathPtr'.
PathPtr = getenv ("PATH"); // Get the value of the environment variable "PATH" and assign it to 'PathPtr'.
if (PathPtr!=NULL) // Check if 'PathPtr' is not NULL (i.e., if the environment variable was found).
printf ("\nThe set path is: %s\n\n",PathPtr); // Print the value of the environment variable "PATH".
return 0; // Return 0 to indicate successful execution of the program.
} // End of the main function.
Sample Output:
The set path is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
Flowchart:
C Programming Code Editor:
Previous: Write a C program to return the absolute value of a long integer.
Next: Write a C program to find the quotient and remainder of a division.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics