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.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join