Re: [C] parsing command line switches
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 01/27/04
- Next message: Joec: "Re: Writing an OO program."
- Previous message: Joec: "Re: Derived Class from a base class..."
- In reply to: Marlene Stebbins: "[C] parsing command line switches"
- Next in thread: Martijn Lievaart: "Re: [C] parsing command line switches"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 26 Jan 2004 19:07:01 -0500 (EST)
On Mon, 26 Jan 2004, Marlene Stebbins wrote:
>
> I haven't found any examples of code that parses command line
> switches. I tried this:
<snip code>
> and it works, but I was wondering if this is anything like the
> conventional method.
I have developed a "boilerplate" code template that I use for
almost all of my own code, which includes things like command-line
switches and "help" and "error exit" functions. See, for example,
http://www.contrib.andrew.cmu.edu/~ajo/free-software/detab.c
.../split_get.c
.../rot13.c
.../quine.c
.../savestruct.c
I'm sure most of the regulars in this newsgroup have similar
"code templates," some probably even better than mine.
For really robust and complicated command-line parsing, I've
heard good things about the 'getopt' library (which is not part
of the C standard library, but would have to be provided by a
third party such as GNU). On the other hand, I've also seen a
lot of newbies saying they can't figure out how to use 'getopt'. ;)
For portability's sake, I stick to my own hand-rolled version
in my code. You're welcome to ad[oa]pt it, if you like.
HTH,
-Arthur
- Next message: Joec: "Re: Writing an OO program."
- Previous message: Joec: "Re: Derived Class from a base class..."
- In reply to: Marlene Stebbins: "[C] parsing command line switches"
- Next in thread: Martijn Lievaart: "Re: [C] parsing command line switches"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|