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,则代表程序正常退出:返回其它数字的含义则由系统决定.通常,返回非零代表程序异常退出. 很多人甚至市面上的一些书籍,都 ...
随机推荐
- java中i=i++字节码分析
原文出处: Ticmy 1 2 int i = 0; i = i++; 结果还是0为什么? 程序的执行顺序是这样的:因为++在后面,所以先使用i,"使用"的含义就是i++这个表达式 ...
- matlab 获取鼠标位置
转载:http://hi.baidu.com/alec1228/item/68ea36ebe4046f3a86d9deab 第一种途径:ginput()函数 ginput提供了一个十字光标使我们能更精 ...
- Unity 移动端触摸屏操作
Unity 触屏操作 当将Unity游戏运行到IOS或Android设备上时,桌面系统的鼠标左键可以自动变为手机屏幕上的触屏操作,但如多点触屏等操作却是无法利用鼠标操作进行的.Unity的Input类 ...
- 浅谈malloc()与free()
malloc()与free() l 函数原型 malloc函数的函数原型为:void* malloc(unsigned int size),它根据参数指定的尺寸来分配内存块,并且返回一个void型指 ...
- Redis的事务
Redis对事务的支持是部分支持,不想oracle,要么都成功要么都失败,Redis可以部分成功部分失败 1 是什么: 可以一次执行多个命令,本质是一组命令的集合.一个事务中的所有命令都会序列化,按顺 ...
- css-transition和transform实现图片悬浮移动动画
今天在京东首页上看到一个效果,鼠标悬浮在图片上时,图片发生移动,鼠标移走时再移回,并且有一个过渡效果. 貌似很简单,自己做做试试吧 我首先使用的是jquery在鼠标悬浮到图片上给图片增加一个类,这个类 ...
- 【poj1013】 Counterfeit Dollar
http://poj.org/problem?id=1013 (题目链接) 题意 12个硬币中有1个是假的,给出3次称重结果,判断哪个硬币是假币,并且判断假币是比真币中还是比真币轻. Solution ...
- 【uoj58】 WC2013—糖果公园
http://uoj.ac/problem/58 (题目链接) 题意 给定一棵树,每个点有一个颜色,提供两种操作: 1.询问两点间路径上的${\sum{v[a[i]]*w[k]}}$,其中${a[i] ...
- SSD硬盘的4K对齐
4K对应4096 硬盘模式: 一.让SSD运行在AHCI模式下: AHCI,全称Advanced Host Controller Interface,即高级主机控制器接口,相比老旧的“IDE“ 虚拟模 ...
- C#制作验证码
void CodeImage(string code) { if (code == null || code.Trim() == string.Empty) return; System.Drawin ...