How to get system environment variables in C language

tags: C language

File Name: get_env.c
Compile instruction: gcc -std = c99 get_env.c -o get_env.out

#include <stdlib.h>
#include <stdio.h>

static inline int readenv_atoi(char *env) {
  char *p;
  // GetENV function is a function of GCC comes with the STDLIB.H header file.
  if (( p = getenv(env) ))
  	return (atoi(p));
  else
	return(0);
}


int main(int argc, char** argv)
{	
	int numprocs = readenv_atoi("OMP_NUM_THREADS");
	printf("numprocs = %d\n",numprocs);
	return 0;
}

Code Source: Source Code of OpenBlas

Intelligent Recommendation

java get system environment variables

Environment variable   Code   Output  ...

Python Get System Environment Variables

Linux execution Python Gets the way system environment variables.  ...

How to get the language of a Windows operating system for C ++

In the Windows operating system, we can get system language through getSystemDefaultLangID, but maybe you don't know: What setting to modify the system will affect the return value of GetSystemDefault...

java get and set system variables (environment variables)

A, Java environment variables Java Environment variables very simple way: System.getEnv()Get all the environmental variables System.getEnv(key) Get an environment variable Second, the acquisition syst...

More Recommendation

C # get and set environment variables

First understand a concept; in addition to the environment variables can be viewed from the system properties-environment variables; there is also a copy in the registry; The user's environment variab...

Spring - How to get system environment variables and variables in the Application configuration file? (EnvironmentaWare)

problem How do I get system environment variables and variables in the Application configuration file? solve Use EnvironmentaWare. Implement the interface environmentaWare and override the method Sten...

C# Get the system environment

<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top