ChinaUnix.net
相关文章推荐:

getopt函数

PHP getopt函数 短参数 它返回一个包含命令行参数的数组。比如,要获得-a -b 和-c的值,可以这么做: $arguments = getopt("a:b:c:"); 可以用下面的方式运行脚本(有无空格是没有关系的,注意看第一个例子和第二个例子):[code]php test.php -a app -b bar -c car OR php test.php -aapp -bbar -ccar print_r($arguments) [/code]将返回:[code]Array ( [a] => app => bar [c] => car ) [/code]注意: 1.冒...

by 听老歌 - PHP - 2011-05-26 13:32:21 阅读(3065) 回复(0)

php

相关讨论

getopt 函数 函数定义: #include int getopt(int argc, char * const argv[], const char *optstring); extern char *optarg; extern int optind, opterr, optopt; #define _GNU_SOURCE #include int getopt_long(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex); int getopt_long_only(int argc, char * const argv[], ...

by typhoon85 - Linux文档专区 - 2009-04-21 16:08:39 阅读(562) 回复(0)

getopt 函数 函数定义: #include int getopt(int argc, char * const argv[], const char *optstring); extern char *optarg; extern int optind, opterr, optopt; #define _GNU_SOURCE #include int getopt_long(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex); int getopt_long_only(int argc, char * const argv[], ...

by nanqihao - Linux文档专区 - 2009-04-13 20:12:39 阅读(535) 回复(0)

while((ch = getopt(argc,argv,"a:bcde"))!= -1) 与 while((ch = getopt(argc,argv,"a:b:c:d:e"))!= -1) 的区别是?

by anonyaniu - C/C++ - 2008-05-10 21:48:11 阅读(1607) 回复(4)

getopt用法 有关系统调用getopt: 声明: #include int getopt(int argc, char *const argv[], const char *optstring); extern char *optarg; extern int optind, opterr, optopt; 使用方法:在while循环中反复调用,直到它返回-1。每当找到一个有效的选项字母,它就返回这个字母。如果选项有参数,就设置optarg指向这个参数。 当程序运行时,getopt()函数会设置控制错误处理的几个变量: ...

by shuhui0614 - Linux文档专区 - 2008-01-29 13:35:25 阅读(829) 回复(0)

象xxx -h host --password 123456这种命令,编程时,如何方便的取得命令行参数?有一个很好的方法,就是调用getopt()。 函数定义: #include int getopt(int argc, char * const argv[], const char *optstring); extern char *optarg; extern int optind, opterr, optopt; #define _GNU_SOURCE #include int getopt_long(int argc, char * const argv[], const char *optstring, const struct opti...

by jesse- - Linux文档专区 - 2006-08-14 17:35:15 阅读(654) 回复(0)

越详细越好,多谢

by los - C/C++ - 2005-05-05 17:36:09 阅读(938) 回复(6)

在实际程序之中我们经常要对命令行参数进行分析. 比如我们有一个程序a可以接受许多参数.一个可能的情况是 a -d print --option1 hello --option2 world 那么我们如何对这个命令的参数进行分析呢?经常用函数getoptgetopt_long. 一、函数定义 相关的函数、数据结构、以及几个全局变量定义在/usr/include/getopt.h中。 #include //函数的实现应该在这个库里 #include //函数声明 int getopt(int argc,char const *...

by wqfhenanxc - Linux文档专区 - 2009-06-20 16:26:36 阅读(895) 回复(0)

作者写得很好。 每一天你都在使用大量的命令行程序,是不是感觉那些命令行参数用起来比较方便,他们都是使用getopt来实现的。 在Linux下使用getopt写程序是一种比较cool的事情,下面来简单的介绍一下getopt的使用。 === getopt使用 === 在讨论参数处理之前,我们先明确两个概念:选项、选项参数 gcc -g -o test test.c 我们经常使用上面的命令来编译程序,这里g和o就是选项,其中test就是o的选项参数 下面我们来看一下getopt: 首先...

by kingkobe08 - Linux文档专区 - 2009-10-20 09:33:10 阅读(1544) 回复(0)

20 世纪 90 年代,UNIX 应用程序开始支持长选项,即一对短横线、一个描述性选项名称,还可以包含一个使用等号连接到选项的参数。 GNU提供了getopt-long()和getopt-long-only()函数支持长选项的命令行解析,其中,后者的长选项字串是以一个短横线开始的,而非一对短横线。 getopt_long() 是同时支持长选项和短选项的 getopt() 版本。下面是它们的声明: #i nclude int getopt_long(int ar...

by 虑而后能得 - Linux文档专区 - 2009-03-19 16:08:17 阅读(758) 回复(0)

#include #include int main( int ac, char **av ) { int opt; while( (opt = getopt( ac, av, "ivhf:ka" )) != -1 ){ switch( opt ){ case 'i': case 'v': case 'k': case 'a': case 'h': printf("option: %c\n", opt ); break; ...

by iamyu10 - C/C++ - 2008-12-22 15:40:07 阅读(1188) 回复(8)