struct option 的使用
2016-03-23 11:38
309 查看
#include <stdio.h> #include <getopt.h> char *l_opt_arg; char* const short_options = "nl:b"; //我设置l是要接参数的。所以l后面有个冒号 //l: means after l there should hava an argument struct option long_options[] = { { "name", 0, NULL, 'n' }, { "bf_name", 0, NULL, 'b' }, { "love", 1, NULL, 'l' }, //1表示require argument ,l后面需要接参数 { 0, 0, 0, 0}, }; int main(int argc, char *argv[]) { int c; while((c = getopt_long (argc, argv, short_options, long_options, NULL)) != -1) { switch (c) { case 'n': printf("My name is AA.\n"); break; case 'b': printf("Her name is BB.\n"); break; case 'l': l_opt_arg = optarg; printf("Our love is %s!\n", l_opt_arg); //l_opt_arg为l后面输入的参数 break; } } return 0; }
实际效果:
相关文章推荐
- org.apache.cxf.interceptor.Fault: The given SOAPAction ... does not match an operation
- OpenMP
- nginx动静分离
- linux-file_operations结构体分析记录
- OP-TEE在HIKEY上的编译、运行与测试
- 2015 年度新增开源软件排名 TOP 100、记录以备不时之需
- 高仿微信5.2.1主界面架构 包含消息通知
- 据称谷歌为移动应用,网站开发者推出新设计的门户网站
- openwrt(路由器)的源码地址
- Ubuntu14.04安装和配置Tomcat8.0.12
- linux device tree源代码解析
- lvs+nginx负载均衡部署
- [linux]cmake make
- Linux 文件查找 find
- linux 内核移植和根文件系统的制作
- Bash脚本学习(1)
- Linux中关于JAVA调用C生成的.so动态链接库
- 用python实时获取shell命令的输出[rsync备份进度]
- centos64位 安装python mysql-client环境
- Linux Shell编程基础