如何通过命令行,为程序传入参数,可以使用函数getopt与getopt_long。

函数的声明如下:

#include <unistd.h>

       int getopt(int argc, char * const argv[],
const char *optstring); extern char *optarg;
extern int optind, opterr, optopt; #include <getopt.h> int getopt_long(int argc, char * const argv[],
const char *optstring,
const struct option *longopts, int *longindex); int getopt_long_only(int argc, char * const argv[],
const char *optstring,
const struct option *longopts, int *longindex);

函数getopt能够输入,类似“-r”, “-h”之类的短参数,如果需要输入长参数,如--help”就用函数getopt_long。

更详细的用法,建议man getopt。

但是我手上有个需求是,传入多个参数,如下面命令来连续读出16个寄存器的取值。

./mem_rdwr.out --rd 0x70006d00 

看上去用getopt实现不了,还是自己手写程序来解析吧

getopt与getopt_long的更多相关文章

  1. 命令行参数处理-getopt()和getopt_long()

    在实际编程当中,自己编写代码处理命令行参数是比较麻烦且易出错的.一般我们会直接使用getopt()和getopt_long()函数,下文将介绍具体的使用方法. getopt() getopt()用于处 ...

  2. 命令行参数解析函数getopt和getopt_long函数【转】

    原文地址:http://blog.csdn.net/cashey1991/article/details/7942809 getopt和getopt_long函数   平时在写程序时常常需要对命令行参 ...

  3. webbench源码学习-->命令行选项解析函数getopt和getopt_long函数

    对于webbench这个网站压力测试工具网上介绍的很多,有深度详解剖析的,对于背景就不在提了, 听说最多可以模拟3万个并发连接去测试网站的负载能力,这里主要是学习了一下它的源码,做点 笔记. 官方介绍 ...

  4. Linux getopt()函数 getopt_long()函数---转

    http://hi.baidu.com/scoundrelgg/item/d4083f8412eea05d26ebd97f Linux getopt()函数 getopt_long()函数 get_o ...

  5. C语言中getopt()和getopt_long()函数的用法

    一.参考文章 1.C语言中getopt()和getopt_long()函数的用法 2.linux 中解析命令行参数 (getopt_long用法) 二.调试经验

  6. 命令行选项解析函数(C语言):getopt()和getopt_long()

    命令行选项解析函数(C语言):getopt()和getopt_long() 上午在看源码项目webbench时,刚开始就被一个似乎挺陌生函数getopt_long()给卡住了,说实话这函数没怎么见过, ...

  7. getopt、getopt_long和getopt_long_only

    GNU/Linux的命令行选项有两种类型:短选项和长选项,前者以 '-' 作为前导符,后者以 '--' 作为前导符.比如有一个命令: $ myprog -a vv --add -b --file a. ...

  8. 命令行參数选项处理:getopt()及getopt_long()函数使用

         在执行某个程序的时候,我们通常使用命令行參数来进行配置其行为.命令行选项和參数控制 UNIX 程序,告知它们怎样动作. 当 gcc的程序启动代码调用我们的入口函数 main(int argc ...

  9. getopt和getopt_long参数处理

    1:getopt函数 getopt主要用于解析程序运行时所带的参数,原型如下: #include <unistd.h> int getopt(int argc, char * const ...

随机推荐

  1. Jacob工具类使用文件互转服务 word转html html转excel word转pdf excel转pdf ppt转pdf

    前提条件  必须安装MS office 1.jdk使用jdk1.8 2.jacob.dll放在..\jdk1.8\jre\bin目录下 3.eclipse的jre版本要和jdk一致,window-&g ...

  2. Java 架构师眼中的 HTTP 协议

    HTTP 协议的内容比较多,本文我们将分六部分来介绍. HTTP 协议的基本内容 什么是 HTTP 协议 首先我们来看协议是什么?协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守有规则的文 ...

  3. 常见性能优化策略的总结 good

    阅读目录 代码 数据库 缓存 异步 NoSQL JVM调优 多线程与分布式 度量系统(监控.报警.服务依赖管理) 案例一:商家与控制区关系的刷新job 案例二:POI缓存设计与实现 案例三:业务运营后 ...

  4. nake_api_protect 请求保护器——防止请求被恶意刷

    github : https://github.com/xjnotxj/wechat_interaction_auth -- nake_api_protect 接口请求保护器,根据 频率 + 次数 的 ...

  5. tkinter中布局pack、place和grid(八)

    tkinter中布局pack.place和grid pack布局 import tkinter wuya = tkinter.Tk() wuya.title("wuya") wuy ...

  6. python教你用微信每天给女朋友说晚安

    但凡一件事,稍微有些重复.我就考虑怎么样用程序来实现它. 这里给各位程序员朋友分享如何每天给朋友定时微信发送"晚安",故事,新闻,等等··· ···最好运行在服务器上,这样后台挂起 ...

  7. 解决python2.x用urllib2证书验证错误, _create_unverified_context

    解决以下错误: 错误1:AttributeError: 'module' object has no attribute '_create_unverified_context', 错误2:URLEr ...

  8. http_server.go

    , fmt.Sprintf("%s: closing %s", proto, listener.Addr())) }

  9. fasthttp 文档手册

    fasthttp 文档手册 貌似文章有最大长度限制,完整全文地址:https://github.com/DavidCai1993/my-blog/issues/35 常量 const ( Compre ...

  10. C# WinForm ShowInTaskbar Api Version

    using System; using System.Runtime.InteropServices; namespace x { unsafe class NativeWindow { /* * W ...