C语言getopt()函数的使用
定义函数
函数说明
返回值
范例
- #include <stdio.h>
- #include <unistd.h>
- int main(int argc, int *argv[])
- {
- int ch;
- opterr = 0;
- while ((ch = getopt(argc,argv,"a:bcde"))!=-1)
- {
- switch(ch)
- {
- case 'a':
- printf("option a:'%s'\n",optarg);
- break;
- case 'b':
- printf("option b :b\n");
- break;
- default:
- printf("other option :%c\n",ch);
- }
- }
- printf("optopt +%c\n",optopt);
- }
执行:
- $ ./getopt -a
- other option :?
- optopt +a
- $ ./getopt -b
- option b :b
- optopt +
- $ ./getopt -c
- other option :c
- optopt +
- $ ./getopt -d
- other option :d
- optopt +
- $ ./getopt -abcd
- option a:'bcd'
- optopt +
- $ ./getopt -bcd
- option b :b
- other option :c
- other option :d
- optopt +
- $ ./getopt -bcde
- option b :b
- other option :c
- other option :d
- other option :e
- optopt +
- $ ./getopt -bcdef
- option b :b
- other option :c
- other option :d
- other option :e
- other option :?
- optopt +f
C语言getopt()函数的使用的更多相关文章
- C语言-getopt函数
#include<unistd.h> int getopt(int argc,char *const argv[],const char *optstring); extern char ...
- linux C语言getopt()函数的使用
getopt被用来解析命令行选项参数. #include <unistd.h> 函数及参数介绍 extern char *optarg; //选项的参数指针,如果选项字符串里的字母后接着冒 ...
- 如何写好 C语言 main 函数!你准备好编写 C 程序了吗?
学习如何构造一个 C 文件并编写一个 C main 函数来成功地处理命令行参数. 我知道,现在孩子们用 Python 和 JavaScript 编写他们的疯狂"应用程序".但是 ...
- C语言pow函数编写
C语言pow函数编写 #include<stdio.h> double chaoba(double f,double q); //声明自定义函数 void main(void) { dou ...
- C语言-自定义函数
C语言自定义函数 --1-- 自定义函数定义 1.1 无参无返回值函数 1.2 无参有返回值函数 1.3 有参无返回值函数 1.4 有参有返回值函数 --2-- 函数的参数 2.1 形式参数介绍和使用 ...
- C语言printf()函数:格式化输出函数
C语言printf()函数:格式化输出函数 头文件:#include <stdio.h> printf()函数是最常用的格式化输出函数,其原型为: int printf( char ...
- getopt函数的使用——分析命令行参数
getopt(分析命令行参数) getopt(分析命令行参数) 短参数的定义 返回值 范例 getopt_long 相关函数表头文件#include<unistd.h> 函数声明int g ...
- C语言的函数
"函数"在英文的翻译是"function",无论在自然科学还是计算机科学都是这个词,而"function"的本意是"功能" ...
- c语言main函数返回值、参数详解(返回值是必须的,0表示正常退出)
C语言Main函数返回值 main函数的返回值,用于说明程序的退出状态.如果返回0,则代表程序正常退出:返回其它数字的含义则由系统决定.通常,返回非零代表程序异常退出. 很多人甚至市面上的一些书籍,都 ...
随机推荐
- LightOJ 1341 唯一分解定理
Aladdin and the Flying Carpet Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld &a ...
- 4位组合型Excel文档密码怎么破解
现代社会我们会遇到各种密码,很多的密码我们一段时间不用就不知不觉的忘记了.很多的excel用户就遇到过这种情况,这个时候我们就需要一款Excel密码破解工具.Advanced Office Passw ...
- cufflinks install
liuhui@pine:~/bin/cufflinks-master$ ./configure --with-bam=/usr/local/include/bam checking for a BSD ...
- Python 学习笔记9(装饰器,decorator)
31 装饰器 装饰器可以对一个函数.方法或者类进行加工,是一种高级的python语法. 装饰函数 接收一个可调用对象作为输入参数,并返回一个新的可调用对象. 把函数传递给装饰器,然后增加新的功能,返回 ...
- 【BZOJ-4547】小奇的集合 矩阵乘法 + 递推
4547: Hdu5171 小奇的集合 Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 175 Solved: 85[Submit][Status][D ...
- 【BZOJ-1009】GT考试 KMP+DP+矩阵乘法+快速幂
1009: [HNOI2008]GT考试 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2745 Solved: 1694[Submit][Statu ...
- O(nlogn)LIS及LCS算法
morestep学长出题,考验我们,第二题裸题但是数据范围令人无奈,考试失利之后,刻意去学习了下优化的算法 一.O(nlogn)的LIS(最长上升子序列) 设当前已经求出的最长上升子序列长度为len. ...
- MVC重写DefaultModelBinder实现自定义模型绑定
在编写前台页面的时候为了使url传递参数的简短,比如personId="1" 我们通过url传递成pid=1 那么在后台action方法接受的模型Person类 的属性为per ...
- 用python来调试网络程序
需要联调的程序,沟通联调起来总是各种麻烦,如果自己能写个简单一点的“测试机”,事情就很easy了:或者有时候想做“中间人”,看看网路上到底传些什么.前面写了串口的测试机,今天尝试了一下UDP的. im ...
- GitBash上传代码不计入贡献的问题处理
发现最近写的代码,通过GitBash上传到github,但是格子确一个都没亮,今天通过一番检索解决了此问题,特做记录: 通过这篇文章找到了原因所在: GitHub 更新代码到底怎样才算贡献? 通过这篇 ...