bodybo的专栏

做喜欢的事

C中获得和修改环境变量(MSDN)

/* GETENV.C: This program uses getenv to retrieve
 * the LIB environment variable and then uses
 * _putenv to change it to a new value.
 */

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

void main( void )
{
   char *libvar;

   /* Get the value of the LIB environment variable. */
   libvar = ( "LIB" );

   if( libvar != NULL )
      printf( "Original LIB variable is: %s/n", libvar );

   /* Attempt to change path. Note that this only affects the environment
    * variable of the current process. The command processor's environment
    * is not changed.
    */
   ( "LIB=c://mylib;c://yourlib" );

   /* Get new value. */
   libvar = getenv( "LIB" );

   if( libvar != NULL )
      printf( "New LIB variable is: %s/n", libvar );
}

Output

Original LIB variable is: C:/progra~1/devstu~1/vc/lib
New LIB variable is: c:/mylib;c:/yourlib
 
阅读更多
文章标签: c command null output
个人分类: C/C++
上一篇JNI中文处理问题小结(转载)
下一篇文件操作API函数(转载)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭