C program to print environment variables

CServer Side ProgrammingProgramming

Here, we will create a c program to print environment variables.

Environment variable is a global variable that can affect the way the running process will behave on the system.

Program to print environment variables

//Program to print environment variables

Example

 Live Demo

#include <stdio.h>
int main(int argc, char *argv[], char * envp[]){
   int i;
   for (i = 0; envp[i] != NULL; i++)
   printf("\n%s", envp[i]);
   getchar();
   return 0;
}

Output

ALLUSERSPROFILE=C:\ProgramData
CommonProgramFiles=C:\Program Files\Common Files
HOMEDRIVE=C:
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 42 Stepping 7, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=2a07
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
WATCOM=C:\watcom
windir=C:\Windows
raja
Published on 18-Jul-2020 05:57:36
Advertisements