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,则代表程序正常退出:返回其它数字的含义则由系统决定.通常,返回非零代表程序异常退出. 很多人甚至市面上的一些书籍,都 ...
随机推荐
- mysql-利润set变量模拟分组查询每组中的第N条数据
查询思路: 很多时候想在使用group by时想查询group by的每一组中的第N条数据,而取这些数据时往往按如下方式去执行则很慢 ; 按如上方式,对于数据10000左右的表就已经很吃不消. 或已拼 ...
- 【USACO 1.4】Arithmetic Progressions
/* TASK: ariprog LANG:C++ URL:http://train.usaco.org/usacoprob2?a=PA9lOcZrdWq&S=ariprog SOLVE:平方 ...
- 【HDU 5855】Less Time, More profit(网络流、最小割、最大权闭合子图)
Less Time, More profit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- ubuntu下lamp配置
apache 在Ubuntu Linux上用 apt-get install apache2 安装Apache2后,竟然发现没有httpd.conf(位于/etc/apache2目录) Ubuntu的 ...
- 【BZOJ-3709】Bohater 贪心
3709: [PA2014]Bohater Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 835 Solved: ...
- 使用reids结合wcf实现集群模式下的聊天室功能
1.reids的特点 Redis数据库完全在内存中,使用磁盘仅用于持久性. 相比许多键值数据存储,Redis拥有一套较为丰富的数据类型(字符串,哈希,列表,集合,有序集合),. Redis可以将数据复 ...
- http80端口转发(实现微信公众号接口绑定IP时,同时支持多个公众号)
http80端口转发 背景 微信公众平台接口绑定服务器时,如果使用IP需要使用80端口,此组件可实现一个IP上绑定多个公众平台接口 使用方法 http://(IP)/WeixinMP/(转发的地址Ba ...
- 更改codeblocks的配色方案
codeblocks默认只有一种配色方案, 不过我们可以手动添加. 在终端下输入如下命令: cd ~/.codeblocks sudo gedit default.conf 在打开的配置文件中, 找到 ...
- OrCAD Capture使用记录
1.安装 ①修改host_ID为主机名称(如果填不对,安装过程会提示你再填一次):其后跟的是机子的MAC地址,用ipconfig /all 可以查看. ②下一行的FLEMlm,后面跟的是文件cdslm ...
- Session对象
Session对象用于存储在多个页面调用之间特定用户的信息.Session对象只针对单一网站使用者,不同的客户端无法互相访问.Session对象中止于联机机器离线时,也就是当网站使用者关掉浏览器或超过 ...