Linux C library function Encyclopedia: Environmental variable Control function

Source: Internet
Author: User

1.GETENV (Get environment variable content)

Related functions:

Putenv,setenv,unsetenv

Table header file:

#include <stdlib.h>

To define a function:

char * getenv (const char *name);

Function Description:

Getenv () is used to get the contents of the parameter name environment variable. The parameter name is the name of the environment variable, and a pointer to that content is returned if the variable exists. The format of the environment variable is name=value.

return value:

Successful execution returns a pointer to the content, and null if no match is found for the environment variable name.

Example:

#include <stdio.h> 
#include <sys/types.h> 
#include <sys/stat.h> 
#include <fcntl.h > 
#include <stdlib.h> 
main () 
{ 
    char *p; 
    if (p = getenv ("USER")) 
        printf ("user=%s\n", p); 

2.putenv (change or increase environment variable)

Related functions:

Getenv,setenv,unsetenv

Table header file:

#include4 <stdlib.h>

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/C/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.