linux之getopt_long函数
来源:互联网 发布:windows nt可以删除吗 编辑:程序博客网 时间:2024/06/07 01:53
原文地址::http://blog.csdn.net/mr_jj_lian/article/details/6835352
相关文章
1、getopt和getopt_long函数----http://blog.csdn.net/cashey1991/article/details/7942809
2、linux之getopt 函数----http://blog.csdn.net/mr_jj_lian/article/details/6835137
getopt_long(int argc,char * const argv[],const char * shortopts,const struct option *longopts,int *longindex)
下面介绍各个参数的含义:
const char *name;
int has_arg;
int *flag;
int val;
};
{ "help", 0, NULL, 'h' },
{ "output", 1, NULL, 'o' },
{ "version", 0, NULL, 'v' },
{ NULL, 0, NULL, 0 }
};
1 每碰到一个命令行参数,optarg都会记录它
'?' 无效选项
':' 缺少选项参数
'x' 选项字符'x'
-1 选项解析结束
一般的用法为while(getopt_long() != -1){},可以通过switch语句来对该函数不同的返回值(即不同的短选项)调用不同的处理函数。
#include <stdio.h>
#include <unistd.h>
#define _GNU_SOURCE
#include <getopt.h>
int main(int argc,char *argv[])
{
int opt;
struct option longopts[] = {
{"initialize",0,NULL,'1'},
{"file",1,NULL,'f'},
{"list",0,NULL,'1'},
{"restart",0,NULL,'r'},
{0,0,0,0}}:
while((opt = getopt_long(argc, argv, "if:lr", longopts, NULL)) != -1){
switch(opt){
case 'i':
case 'l':
case 'r':
printf("option: %c\n",opt);
break;
case 'f':
printf("filename: %s\n",optarg);
break;
case ':':
printf("option needs a value\n");
break;
case '?':
printf("unknown option: %c\n",optopt);
break;
}
for(; optind < argc; optind++){
printf("argument: %s\n",argv[optind]);
}
exit(0);
}
- linux之getopt_long函数
- linux之getopt_long函数
- linux之getopt_long函数解析
- Linux getopt_long函数调用
- linux 之 getopt_long()
- getopt_long函数基本用法-linux
- Linux getopt和getopt_long函数
- Webbech学习之getopt_long函数
- Linux getopt()函数 getopt_long()函数---转
- Linux下命令行程序设计--getopt_long()函数使用说明
- Linux选项解释-getopt和getopt_long函数
- Linux选项解释-getopt和getopt_long函数
- Linux编程里getopt_long函数用法详解
- linux选项解释-getopt和getopt_long函数
- linux中函数getopt_long用法解释
- getopt_long函数
- getopt_long函数
- 命令行处理之getopt和getopt_long函数
- 安装Cocoapods, 更新gem出现的问题
- 138.Simplify Path
- java super 用法
- UVA, 10286 Trouble with a Pentagon
- 如何从文本里提出无重复的关键词,并保持原始排序
- linux之getopt_long函数
- linux数据库和文件夹定时备份删除
- 正被停用的激活上下文不是最近激活的
- 联想搜索
- 自定义View的旅程-canvas画弧线
- spring源码之—Assert.notNull
- 关于Android中设置闹钟的相对完善的解决方案
- Java多线程学习
- PHP json_encode中文乱码解决方法