« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
| 公告 |
☆★☆★☆★☆★☆★☆ 生活的点点记录,以及一些体会...........
喜欢是淡淡的爱,爱是深深的喜欢.
时间会见证一切.......................
欢迎大家指出错误,共同进步..........
期待中..............................
☆★☆★☆★☆★☆★☆ |
Blog信息 |
blog名称: 日志总数:162 评论数量:312 留言数量:0 访问次数:941974 建立时间:2005年5月17日 |

| |
[Linux]getopt() 函数介绍 文章收藏
oceanblue 发表于 2006/10/25 14:31:37 |
getopt
(分析命令参数)
相关函数
表头文件
#include<unistd.h>
定义函数
int getopt(int argc,char * const argv[ ],const char * optstring);
函数说明
getopt()用来分析命令行参数。参数argc和argv是由main()传递的参数个数和内容。参数optstring 则代表欲处理的选项字符串。此函数会返回在argv 中下一个的选项字母,此字母会对应参数optstring 中的字母。如果选项字符串里的字母后接着冒号“:”,则表示还有相关的参数,全域变量optarg 即会指向此额外参数。如果getopt()找不到符合的参数则会印出错信息,并将全域变量optopt设为“?”字符,如果不希望getopt()印出错信息,则只要将全域变量opterr设为0即可。
返回值
如果找到符合的参数则返回此参数字母,如果参数不包含在参数optstring 的选项字母则返回“?”字符,分析结束则返回-1。
范例
#include<stdio.h>#include<unistd.h>int main(int argc,char **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);}
执行
$./aaa –boption b:b$./aaa –cother option:c$./aaa –aother option :?$./aaa –a12345option a:’12345’ |
|
回复:getopt() 函数介绍 文章收藏
q(游客)发表评论于2010/1/13 13:07:40 |
孙永清 北京华江恒泰 华江恒泰 北京威龙 上海弗泰 上海弗泰 北京嘉华 上海申延机械 北京华科 北创沃得 北创沃得 北京百年华典 空调安装 液压 剪板机 北京空调加氟 北京空调清洗 模温机 收药 台湾液压 液压元件 |
|
回复:getopt() 函数介绍 文章收藏
zz(游客)发表评论于2009/6/10 20:24:27 |
jeux de fille
juegos de ni as
giochi per ragazze |
|
回复:getopt() 函数介绍 文章收藏
av(游客)发表评论于2009/5/18 11:10:21 |
|
回复:getopt() 函数介绍 文章收藏
zrkkfc(游客)发表评论于2009/3/8 19:04:22 |
好文,收藏了!
document.write("");
ringsignaler
document.write("");
|
|
回复:getopt() 函数介绍 文章收藏
zrkkfc(游客)发表评论于2009/3/8 19:03:37 |
好文,收藏了!
document.write("");
ringsignaler
document.write("");
|
|
» 1 »
|