15.htm ( File view )

  • By 2010-08-02
  • View(s):4
  • Download(s):0
  • Point(s): 1
			<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0056)http://linux.tcpip.com.cn/~foolox/c_fun/function/15.html -->
<HTML><HEAD><TITLE>Untitled Document</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY>
<TABLE width="100%">
  <TBODY>
  <TR>
    <TD vAlign=top width=80>  
      <DIV align=right><BR><FONT face=宋体 size=2><A 
      name=linuxc289></A></FONT></DIV></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2><BR></FONT></DIV></TD>
    <TD><FONT face=宋体 size=2><BR>getenv(取得环境变量内容) </FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>相关函数 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>putenv,setenv,unsetenv<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>表头文件 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>#include&lt;stdlib.h&gt;<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>定义函数 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>char * getenv(const char *name);<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>函数说明 </FONT></DIV></TD>
    <TD><FONT face=宋体 
      size=2>getenv()用来取得参数name环境变量的内容。参数name为环境变量的名称,如果该变量存在则会返回指向该内容的指针。环境变量的格式为name=value。<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>返回值 </FONT></DIV></TD>
    <TD><FONT face=宋体 
  size=2>执行成功则返回指向该内容的指针,找不到符合的环境变量名称则返回NULL。<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>范例 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>#include&lt;stdlib.h&gt;<BR>mian()<BR>{
<BR>char 
      *p;<BR>if((p = 
    getenv(“USER”)))<BR>printf(“USER=%s\n”,p);<BR>
}<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>执行 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>USER = root<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>  
      <DIV align=right><BR><FONT face=宋体 size=2><A 
      name=linuxc290></A></FONT></DIV></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2><BR></FONT></DIV></TD>
    <TD><FONT face=宋体 size=2><BR>putenv(改变或增加环境变量) </FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>相关函数 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>getenv,setenv,unsetenv<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>表头文件 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>#include4&lt;stdlib.h&gt;<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>定义函数 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>int putenv(const char * string);<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>函数说明 </FONT></DIV></TD>
    <TD><FONT face=宋体 
      size=2>putenv()用来改变或增加环境变量的内容。参数string的格式为name=value,如果该环境变量原先存在,则变量内容会依参数string改变,否则此参数内容会成为新的环境变量。<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>返回值 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>执行成功则返回0,有错误发生则返回-1。<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>错误代码 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>ENOMEM 内存不足,无法配置新的环境变量空间。<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>范例 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>#include&lt;stdlib.h&gt;<BR>main()<BR>{
<BR>char 
      *p;<BR>if((p = getenv(“USER”)))<BR>printf(“USER 
      =%s\n”,p);<BR>putenv(“USER=test”);<BR>printf(“USER+5s\n”,getenv(“USER”));<BR>
}<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2>执行 </FONT></DIV></TD>
    <TD><FONT face=宋体 size=2>USER=root<BR>USER=root<BR></FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>  
      <DIV align=right><BR><FONT face=宋体 size=2><A 
      name=linuxc291></A></FONT></DIV></TD></TR>
  <TR>
    <TD vAlign=top width=80>
      <DIV align=right><FONT face=宋体 size=2><BR></FONT></DIV></TD>
    <TD><FONT face=宋体 size=2><BR>setenv(改变或增加环境变量) </FONT></TD></TR>
  <TR>
    <TD vAlign=top width=80>
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
Linux-C函数-信号处理篇.htm552.00 B19-05-08|10:27
Linux-C函数-内存及字符串操作篇.htm568.00 B19-05-08|10:27
Linux-C函数-内存控制篇.htm552.00 B19-05-08|10:27
Linux-C函数-字符串转换篇.htm556.00 B19-05-08|10:27
Linux-C函数-字符测试篇.htm552.00 B19-05-08|10:27
Linux-C函数-常用数学函数篇.htm560.00 B19-05-08|10:27
Linux-C函数-接口处理篇.htm552.00 B19-05-08|10:27
Linux-C函数-数据结构及算法篇.htm564.00 B19-05-08|10:27
Linux-C函数-文件内容操作篇.htm560.00 B19-05-08|10:27
Linux-C函数-文件操作篇.htm552.00 B19-05-08|10:27
Linux-C函数-文件权限控制篇.htm560.00 B19-05-08|10:27
Linux-C函数-日期时间篇.htm552.00 B19-05-08|10:27
Linux-C函数-环境变量篇.htm552.00 B19-05-08|10:27
Linux-C函数-用户组篇.htm548.00 B19-05-08|10:27
Linux-C函数-终端控制篇.htm552.00 B19-05-08|10:27
Linux-C函数-进程操作篇.htm552.00 B19-05-08|10:27
11.htm72.14 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
16.htm9.46 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
07.htm76.70 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
15.htm6.96 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
04.htm18.86 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
12.htm67.83 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
09.htm30.28 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
10.htm49.96 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
08.htm18.21 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
14.htm58.14 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
06.htm39.94 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
01.htm27.35 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
02.htm23.47 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
03.htm14.07 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
05.htm58.64 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
13.htm40.40 kB19-05-08|10:27
left.htm36.58 kB19-05-08|10:27
Linux-C函数-进程操作篇.files0.00 B11-08-08|17:48
Linux-C函数-终端控制篇.files0.00 B11-08-08|17:48
Linux-C函数-用户组篇.files0.00 B11-08-08|17:48
Linux-C函数-环境变量篇.files0.00 B11-08-08|17:48
Linux-C函数-日期时间篇.files0.00 B11-08-08|17:48
Linux-C函数-文件权限控制篇.files0.00 B11-08-08|17:48
Linux-C函数-文件操作篇.files0.00 B11-08-08|17:48
Linux-C函数-文件内容操作篇.files0.00 B11-08-08|17:48
Linux-C函数-数据结构及算法篇.files0.00 B11-08-08|17:48
Linux-C函数-接口处理篇.files0.00 B11-08-08|17:48
Linux-C函数-常用数学函数篇.files0.00 B11-08-08|17:48
Linux-C函数-字符测试篇.files0.00 B11-08-08|17:48
Linux-C函数-字符串转换篇.files0.00 B11-08-08|17:48
Linux-C函数-内存控制篇.files0.00 B11-08-08|17:48
Linux-C函数-内存及字符串操作篇.files0.00 B11-08-08|17:48
Linux-C函数-信号处理篇.files0.00 B11-08-08|17:48
Linux-C0.00 B11-08-08|17:48
...
Sponsored links

15.htm (131.54 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D