getopt函数
#include <unistd.h> extern char *optarg;
extern int optind, opterr, optopt;
int getopt(int argc, char * const argv[], const char *optstring);
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h> int main(int argc, char *argv[])
{
extern char *optarg;
extern int optind, opterr, optopt;
int i;
int ret; for (i=; i<argc; i++)
{
printf ("argv[%d] %s\n", i, argv[i]);
}
printf ("\n"); while ((ret = getopt(argc, argv, ":a:b::c")) != -)
{
switch (ret) {
case 'a':
printf ("option: %c argv: %s\n", ret, optarg);
break;
case 'b':
if (optarg)
printf ("option: %c argv: %s\n", ret, optarg);
else
printf ("option: %c no argument\n", ret);
break;
case '?':
printf ("encountered a unrecognized option: %c, argv: %s\n", optopt, argv[optind - ]);
break;
case ':':
printf ("option: %c missing argument\n", optopt);
break;
default:
printf ("option: %c\n", ret);
break;
}
} printf ("\noptind: %d\n\n", optind);
for (i=optind; i> && i<argc; i++)
printf ("argv[%d] %s\n", i, argv[i]); printf ("\n");
for (i=; i<argc; i++)
printf ("argv[%d] %s\n", i, argv[i]); return ;
}
getopt函数的更多相关文章
- getopt函数的使用——分析命令行参数
getopt(分析命令行参数) getopt(分析命令行参数) 短参数的定义 返回值 范例 getopt_long 相关函数表头文件#include<unistd.h> 函数声明int g ...
- Linux c 下使用getopt()函数
命令行参数解析函数 —— getopt() getopt()函数声明如下: #include <unistd.h> int getopt(int argc, char * const ar ...
- Linux下getopt()函数的简单使用
最近在弄Linux C编程,本科的时候没好好学啊,希望学弟学妹们引以为鉴. 好了,虽然啰嗦了点,但确实是忠告.步入正题: 我们的主角----getopt()函数. 英雄不问出处,getopt()函数的 ...
- C语言-getopt函数
#include<unistd.h> int getopt(int argc,char *const argv[],const char *optstring); extern char ...
- 如何使用getopt()函数解析参数
最近在写程序的过程中,把一部分时间都花费在程序对参数的处理上.今天听了学长说到getopt函数,才发现原来c里面还有一个专门解决参数处理的函数,查询了相关资料,这里简单总结一下. 使用int main ...
- liunx 系统调用 getopt() 函数
命令行参数解析函数 -- getopt() getopt()函数声明如下: #include <unistd.h>int getopt(int argc, char * const arg ...
- Python中getopt()函数的使用
在运行程序时,可能需要根据不同的条件,输入不同的命令行选项来实现不同的功能.目前有短选项和长选项两种格式.短选项格式为"-"加上单个字母选项:长选项为"--"加 ...
- [转载]Linux下getopt()函数的简单使用
转载源地址:https://www.cnblogs.com/qingergege/p/5914218.html 1.getopt()函数的出处就是unistd.h头文件(哈哈),写代码的时候千万不要忘 ...
- Linux getopt()函数 getopt_long()函数---转
http://hi.baidu.com/scoundrelgg/item/d4083f8412eea05d26ebd97f Linux getopt()函数 getopt_long()函数 get_o ...
- linux之getopt 函数(转)
命令行参数解析函数 —— getopt() getopt()函数声明如下: #include <unistd.h> int getopt(int argc, char * const ar ...
随机推荐
- Google HTML/CSS Style Guide
转自: http://google.github.io/styleguide/htmlcssguide.xml Google HTML/CSS Style Guide Revision 2.23 Ea ...
- 配平化学方程式的C++代码实现
配平化学方程式的C++代码实现 纪念一下我今天写过了 20171006. (去年的这个时候我就有了这个大胆的想法, 当时的思路是:字符串处理->暴力搜系数,可是太年轻写不对,我那会还是个只会模拟 ...
- Running to the End(Codeforces & AtCoder 百套计划)
...Reserved for the future... 仿照xxy dalao的CF&CC百套计划,做了一个Codeforces & AtCoder 百套计划,按这个速度刷下去,每 ...
- HAOI2010软件安装(树形背包)
HAOI2010软件安装(树形背包) 题意 有n个物品,每个物品最多会依赖一个物品,但一个物品可以依赖于一个不独立(依赖于其它物品)的物品,且可能有多个物品依赖一个物品,并且依赖关系可能形成一个环.现 ...
- Mybatis配置之别名配置元素详述
这里我们贴出之前的UserDao对应的mapper文件,如下所示 从这个配置文件中,我们可以看到<select>.<insert>和<update>三个标签元素的r ...
- Django链接Mysql 8.0 出现错误(1045:Access denied for user 'root'@'localhost' (using password: NO) 的一种解决方法
运行环境: Django版本2.0 ; Mysql 版本 8.0.11; 错误代码: django.db.utils.OperationalError: (1045:Access denied fo ...
- ISAP 算法的学习
http://www.renfei.org/blog/isap.html 算法与数学 网络流-最大流问题 ISAP 算法解释 2013-08-07Renfei Song 2 条评论 内容提要 [隐藏] ...
- 【ACM】nyoj_103_A+BII_201307291022
A+B Problem II时间限制:3000 ms | 内存限制:65535 KB 难度:3描述 I have a very simple problem for you. Given two ...
- 反射常用API
反射所有功能都是通过class API来实现的 class常用API有: 1.class.GETINTERFACES():获得这个类实现的接口. 2.class.getMethods() Method ...
- Android ContextMenu的使用
ContextMenu介绍: 假设一个View注冊了上下文菜单.那么当长按该View时便会弹出一个浮动菜单,来供选择下一步操作. 实现这个功能须要调用setOnCreateContextMenuLis ...