struct option
来源:互联网 发布:淘宝远程刷机价格 编辑:程序博客网 时间:2024/06/08 06:06
struct option
环境:DM365 DVSDK DEMO
文件:Main.c
函数:parseArgs()
在该函数中,初始化结构体数组:const struct option longOptions[],其原型定义在getopt.h中:
#define no_argument 0
#define required_argument 1
#define optional_argument 2
struct option {
const char *name;
int has_arg;
int *flag;
int val;
};
const char *name是不带短横线的选项名,前面没有短横线。譬如“help”、“verbose”之类。
int has_arg 描述了选项是否有选项参数。如果有,是哪种类型的参数,此时,它的值一定是下表中的一个。符号常量数值含义
no_argument 0 选项没有参数
required_argument 1 选项需要参数
optional_argument 2 选项参数可选
int *flag 如果这个指针为NULL,那么getopt_long()返回该结构val字段中的数值。如果该指针不为NULL,getopt_long()会使得它所指向的变量中填入val字段中的数值,并且getopt_long()返回0。如果flag不是NULL,但未发现长选项,那么它所指向的变量的数值不变。
int val 这个值是发现了长选项时的返回值,或者flag不是 NULL时载入*flag中的值。典型情况下,若flag不是NULL,那么val是个真/假值,譬如1 或0;另一方面,如果flag是NULL,那么val通常是字符常量,若长选项与短选项一致,那么该字符常量应该与optstring中出现的这个选项的参数相同。
int main(int argc, char *argv[])
{
int opt;
char filename[512];
int open_flag = 0;
while((opt = getopt(argc, argv, “hf:vo")) != -1) {
switch(opt) {
case ‘v': printf(“ver 3.1”);break;
case ‘h':usage();break;
case ‘o’: open_flag =1 ;break;
case 'f':
printf("filename: %s\n", optarg);
strncpy(filename,optarg,sizeof(filename)-1);
break;
case ‘:’:
printf("option %c needs a value\n ", optopt);
break;
case ‘?’:
printf("unknown option: %c\n", optopt);
break;
}
}
文件:Main.c
函数:parseArgs()
在该函数中,初始化结构体数组:const struct option longOptions[],其原型定义在getopt.h中:
#define no_argument
#define required_argument
#define optional_argument
struct option {
};
const char *name是不带短横线的选项名,前面没有短横线。譬如“help”、“verbose”之类。
int has_arg 描述了选项是否有选项参数。如果有,是哪种类型的参数,此时,它的值一定是下表中的一个。符号常量数值含义
no_argument
required_argument
optional_argument
int *flag
int val 这个值是发现了长选项时的返回值,或者flag不是 NULL时载入*flag中的值。典型情况下,若flag不是NULL,那么val是个真/假值,譬如1 或0;另一方面,如果flag是NULL,那么val通常是字符常量,若长选项与短选项一致,那么该字符常量应该与optstring中出现的这个选项的参数相同。
int main(int argc, char *argv[])
{
- struct option
- struct option
- struct option结构定义
- struct option 的使用
- static struct option opts[] =
- C语言中的struct option结构体
- linux获取命令行参数struct option
- struct option结构体的定义
- 使用getopt_long()从命令行获取参数,struct option
- 使用getopt_long()从命令行获取参数,struct option
- linux 输入参数利用getopt、struct option、getopt_long、getopt_long_only解析
- 使用getopt_long()从命令行获取参数,struct option
- Option
- Option
- Struct
- struct
- struct
- struct
- linux u盘挂载
- 书单
- virtualBox安装Linux并配置
- 获取DataTable中指定位置开始的数据行
- Android中解析XML
- struct option
- C++ 中list、vector和deque比较[转]
- vc中CString的使用
- windows 下python 安装mmseg问题
- 从小事做起,规划你的程序人生
- Chinese scientists discover gut bacteria linked with obesity
- v4l2_field理解
- Android通过Activity栈方式对Activity管理
- 修改java不用重启tomcat的好东西,你值得拥有