getopt_long 函数
#define _GNU_SOURCE #include <getopt.h> extern char *optarg; extern int optind, opterr, optopt; 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[], const char *optstring, const struct option *longopts, int *longindex);
描述:
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
int main(int argc, char **argv)
{
extern char *optarg;
extern int optind, opterr, optopt;
int c;
int digit_optind = ;
while ()
{
int this_option_optind= optind ? optind : ;
int option_index = ;
static struct option long_options[] =
{
{"add", required_argument, NULL, },
{"append", no_argument, NULL, },
{"delete", required_argument, NULL, },
{"verbose", no_argument, NULL, },
{"create", required_argument, NULL, 'c'},
{"file", required_argument, NULL, },
{, , , },
};
c = getopt_long(argc, argv, ":abc:d:012", long_options, &option_index);
if (c == -)
break;
switch (c)
{
case :
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case '':
case '':
case '':
if (digit_optind != && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'c':
printf ("option c with value \"%s\"\n", optarg);
break;
case 'd':
printf ("option d with value \"%s\"\n", optarg);
break;
case '?':
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc) {
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
exit();
}
运行自行操作测试
getopt_long 函数的更多相关文章
- getopt_long函数使用【转】
转自:https://blog.csdn.net/cashey1991/article/details/7942809 平时在写程序时常常需要对命令行参数进行处理,当命令行参数个数较多时,如果按照顺序 ...
- 命令行参数解析函数getopt和getopt_long函数【转】
原文地址:http://blog.csdn.net/cashey1991/article/details/7942809 getopt和getopt_long函数 平时在写程序时常常需要对命令行参 ...
- getopt() getopt_long()函数手册[中文翻译]
getopt()函数 getopt_long函数 函数原型(function prototype) #include <unistd.h> int getopt(int argc, cha ...
- [置顶] getopt_long函数基本用法-linux
一.感性认识: [c-sharp] view plain copy #include <stdio.h> #include <getopt.h> char * l_opt ...
- Linux getopt()函数 getopt_long()函数---转
http://hi.baidu.com/scoundrelgg/item/d4083f8412eea05d26ebd97f Linux getopt()函数 getopt_long()函数 get_o ...
- C语言中getopt()和getopt_long()函数的用法
一.参考文章 1.C语言中getopt()和getopt_long()函数的用法 2.linux 中解析命令行参数 (getopt_long用法) 二.调试经验
- 命令行參数选项处理:getopt()及getopt_long()函数使用
在执行某个程序的时候,我们通常使用命令行參数来进行配置其行为.命令行选项和參数控制 UNIX 程序,告知它们怎样动作. 当 gcc的程序启动代码调用我们的入口函数 main(int argc ...
- webbench源码学习-->命令行选项解析函数getopt和getopt_long函数
对于webbench这个网站压力测试工具网上介绍的很多,有深度详解剖析的,对于背景就不在提了, 听说最多可以模拟3万个并发连接去测试网站的负载能力,这里主要是学习了一下它的源码,做点 笔记. 官方介绍 ...
- getopt_long函数解析命令行参数
转载:http://blog.csdn.net/hcx25909/article/details/7388750 每一天你都在使用大量的命令行程序,是不是感觉那些命令行参数用起来比较方便,他们都是使用 ...
随机推荐
- Linux C(day01)
Linux是一个和Windows类似的操作系统 通常通过终端软件使用Linux操作系统 终端软件里只能使用键盘不能使用鼠标 可以在终端软件里输入各种命令控制计算机 完成各种任务 clear命令可以清除 ...
- 一维数组快速转集合(List)
String[] arr={"qwe","asd","zxc","asddf","hghgf"}; ...
- lucene_07_solr使用IK分词器
使用IKAnalyzer 中文分析器.. 第一步: 把,IKAnalyzer2012FF_u1j 添加到sol/WEB-INF/lib 目录下. 第二步: 复制IKAnalyzer 的配置文件和自定义 ...
- netty自定义协议 心跳 断线重连源码
https://github.com/aa1356889/NettyHeartbeat
- States of Integrity Constraints
States of Integrity Constraints As part of constraint definition, you can specify how and when Oracl ...
- CentOS6.2上安装Oracle10g报ins_emdb.mk错误处理方法
oracle安装过程报ins_emdb.mk错误,此时继续点击“continue”即可,待Oracle完成安装后,再手工执行相应脚本完成链接即可 在CentOS6.2操作系统上,安装Oracle10g ...
- session_start() [function.session-start]:
我在学习PHP的,当我尝试做在session_start() - 获取有关错误信息不能发送会话cookie. 我看到在这个问题上前面的问题,可是,仍然不能确定我的错误. 假设是错误家伙? <? ...
- 黑马day01 笔记
一.xml语法 1.文档声明 用来声明xml的基本属性,用来指挥解析引擎怎样去解析当前xml 通常一个xml都要包括而且仅仅能包括一个文档声明 xml的文档必须在整个xml ...
- linux下的oom调试笔记【原创】
平台信息:内核:linux3.0.68 系统:android/android5.1平台:s5p4418 作者:庄泽彬(欢迎转载,请注明作者) 邮箱:2760715357@qq.com 摘要:调整and ...
- 国内物联网平台初探(一) ——百度物接入IoT Hub
物接入IoT Hub - 架构 全托管的云服务,帮助建立设备与云端之间安全可靠的双向连接 支撑海量设备的数据收集.监控.故障预测等各种物联网场景 物接入IoT Hub - 功能 通信协议:支持MQTT ...