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 ...
随机推荐
- GDI 画笔(9)
使用现有画笔 Windows 提供三种备用画笔(Stock Pen):BLACK_PEN(黑色画笔).WHITE_PEN(白色画笔).NULL_PEN(不绘制任何图形的画笔). 调用 GetStock ...
- 洛谷 P1595 信封问题
题目描述 某人写了n封信和n个信封,如果所有的信都装错了信封.求所有信都装错信封共有多少种不同情况. 输入输出格式 输入格式: 一个信封数n 输出格式: 一个整数,代表有多少种情况. 输入输出样例 输 ...
- mysql 与elasticsearch实时同步常用插件及优缺点对比(ES与关系型数据库同步)
前言: 目前mysql与elasticsearch常用的同步机制大多是基于插件实现的,常用的插件包括:elasticsearch-jdbc, elasticsearch-river-MySQL , g ...
- POJ 2079
呃,不知道我用的算不算卡壳,总有点枚举的意思. 先求凸包,然后,枚举其中一点,再枚举另一点作为结尾,这个向量旋转一周后,求出最大值面积.这里面用的是旋转卡壳判断的那个式子. PS:下一篇和这题是一样题 ...
- JS经常使用表单验证总结
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- WndProc函数参数列表
protected override void WndProc(ref Message m) 实现了这一点. 重写WndProc函数,可以捕捉所有窗口发生的消息.这样,我们就可以"篡改&qu ...
- oc15--文档安装
// // main.m // 修改项目模板 /* 工程名称: 文件名称: 创建者 : 创建时间: 版权 : 修改人 : 修改时间: */ #import <Foundation/Foundat ...
- nyoj--744--蚂蚁的难题(一)
蚂蚁的难题(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 小蚂蚁童鞋最近迷上了位运算,他感觉位运算非常神奇.不过他最近遇到了一个难题: 给定一个区间[a,b],在 ...
- 框架-Java:Spring MVC
ylbtech-框架-Java:Spring MVC Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面.Spring 框架提供了构建 We ...
- libhiredis.so.0.13 => not found 缺少
wget https://github.com/redis/hiredis/archive/v0.13.3.tar.gz tar -xzvf v0.13.3.tar.gz cd hiredis- ma ...