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 每一天你都在使用大量的命令行程序,是不是感觉那些命令行参数用起来比较方便,他们都是使用 ...
随机推荐
- javascript 数组 常用方法
前言 学学忘忘 闲来做个笔记 整理下数组常用方法. Array 数组常用方法 创建数组的基本方式有两种 1.第一种是使用Array构造函数, var arr = new Array(); ...
- 1.git的安装和配置
从git官网下一个git安装包. 点击git.exe安装程序,点击[next] 点击[next] 根据自己的需要可以把需要安装软件全选上,点击[next] 由于这是个人使用所以选择第二 ...
- ExtJs之Ext.comboBox的远程数据源读取程序
既然可以测试本地AJAX,那就把书前面的代码作一次学习吧. <!DOCTYPE html> <html> <head> <title>ExtJs< ...
- POJ 3335
/*半平面交求核心的增量法: 假设前N-1个半平面交,对于第N个半平面,只需用它来交前N-1个平面交出的多边形. 算法开始时,调整点的方向为顺时针方向,对于是否为顺时针,只需求出其面积,若为正,必为逆 ...
- 一个表空间使用率查询sql的优化
话不多说,直接上运行计划: SQL> set lines 500; SQL> set pagesize 9999; SQL> set long 9999; SQL> selec ...
- 项目结构、包、编译为exe!
一个java源文件里至多有一个public类,该类的名称必须与源文件名称称同样.也能够没有public类.文件名称与随意一个类名一致就可以. 包 类似于cpp的namespace,是对类的再封装,防止 ...
- 解决MyEclipse开启后总是不停的在Update index
近期MyEclipse开启之后总是不停的在 update index,非常是耗时间. 查找资料发现Update index...是Maven在不断更新, 解决的方法例如以下: Window --> ...
- bzoj2878 [Noi2012]迷失游乐园 [树形dp]
Description 放假了,小Z认为呆在家里特别无聊.于是决定一个人去游乐园玩. 进入游乐园后.小Z看了看游乐园的地图,发现能够将游乐园抽象成有n个景点.m条道路的无向连通图,且该图中至多有一个环 ...
- Linux命令(六)——软件包管理(安装应用程序)
与windows安装各种应用程序相似,在linux下也可以安装各种需要的应用程序,通常称为软件包.目前,在linux系统下常见的软件包格式主要有:RPM包.TAR包.bz2包.gz包.deb包.sh结 ...
- AWS之VPC、Subnet与CIDR
什么是CIDR? CIDR是英文Classless Inter-Domain Routing的缩写,中文是无类别域间路由,是一个在Internet上创建附加地址的方法,这些地址提供给服务提供商(ISP ...