linux 中解析命令行参数 (getopt_long用法)
来源:互联网 发布:涤纶网络丝的规格 编辑:程序博客网 时间:2024/05/21 10:10
- #include <stdio.h>
- #include <getopt.h>
- char *l_opt_arg;
- char* const short_options = "nbl:";
- struct option long_options[] = {
- { "name", 0, NULL, 'n' },
- { "bf_name", 0, NULL, 'b' },
- { "love", 1, NULL, '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 XL./n");
- break;
- case 'b':
- printf("His name is ST./n");
- break;
- case 'l':
- l_opt_arg = optarg;
- printf("Our love is %s!/n", l_opt_arg);
- break;
- }
- }
- return 0;
- }
[root@localhost liuxltest]# gcc -o getopt getopt.c
[root@localhost liuxltest]# ./getopt -n -b -l forever
My name is XL.
His name is ST.
Our love is forever!
[root@localhost liuxltest]#
[root@localhost liuxltest]# ./getopt -nb -l forever
My name is XL.
His name is ST.
Our love is forever!
[root@localhost liuxltest]# ./getopt -nbl forever
My name is XL.
His name is ST.
Our love is forever!
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数(getopt_long用法)
- linux 中解析命令行参数(getopt_long用法)
- linux中解析命令行参数(getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- linux 中解析命令行参数 (getopt_long用法)
- 什么事都得先打好基础,学习面向对象也是如此
- 局域网内远程调试命令行快速配置
- [转]读Visual C++ 开发经验技巧宝典第二章—-数据类型
- 笑话段子
- 空间任意两点圆滑曲线连接,曲线轴垂直于Y轴
- linux 中解析命令行参数 (getopt_long用法)
- Ubuntu 下TXT中文显示乱码解决方法
- 历史访问CATEGORY
- 理解编译预处理
- symbian下实现自定义模态对话框
- jquery.alerts,不用windows自带的窗体,有回调函数(解决添加收藏夹jquery异步问题)
- oracle redo日志恢复
- 有一种开发的高级技术叫测试
- KEmulator 屏蔽内存查看器功能