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:
#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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/c-programming-exercises/variable-type/c-variable-type-exercises-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics