2013年4月22日
摘要: 我们知道,Linux下的环境变量可以用来控制shell脚本和其他程序的行为。UNIX规范定义了许多标准环境变量,包括终端类型、默认的编辑器、时区等。C语言程序可以通过putenv和getenv函数来访问环境变量。1 #include<stdlib.h>2 extern char **environ;3 char *getenv(const char *name);4 int putenv(const char *string);环境由一组格式为“名字=值”的字符串组成。程序可以通过environ这个变量直接访问这个字符串数组。getenv函数根据给定的名字搜索环境中的一个字符串,并 阅读全文
posted @ 2013-04-22 16:41 Licious 阅读(200) 评论(0) 推荐(0)
摘要: 为了获取程序的参数,Linux C提供了标准编程接口:getopt函数,它支持需要关联值和不许要关联值的选项。下面对函数介绍如下:1 #include<unistd.h> 2 int getopt(int argc,char *const argv[],const char *optstring);3 extern char *optarg;4 extern int optind,opterr,optopt;getopt函数将传递给程序的main函数的argc和argv作为参数,同时接收一个选项制定符字符串optstring,该字符串告诉getopt哪些选项可用,以及他们是否存在关 阅读全文
posted @ 2013-04-22 16:17 Licious 阅读(480) 评论(1) 推荐(0)