From: Fabio <fabio@crearium.com>
To: linux-c-programming@vger.kernel.org
Subject: getopt() library function options
Date: Thu, 03 Mar 2005 22:35:02 -0600 [thread overview]
Message-ID: <1109910902.595.32.camel@0003ba16bccc> (raw)
Hello,
I am coding a small utility for system administrator. The following command line options will be accepted:
$apstat
$apstat -t 1
$apstat -n 1
$apstat -t 2 -n 2
$apstat -v
$apstat -t 1 -v
$apstat -v -t 1 -n 2
unaccepted command line options:
$apstat -t
$apstat -n
$apstat -t <<non integer value>>
$apstat -n <<non integer value>>
I would like that know what would be the while() command that I have to call getopt() inside the case(), for example, I need all this:
while ((c = getopt(argc, argv, ":abf:")) != -1) {
switch(c) {
case 'a':
printf("a is set\n");
break;
case 'b':
printf("b is set\n");
break;
case 'f':
filename = optarg;
printf("filename is %s\n", filename);
break;
case ':':
printf("-%c without filename\n", optopt);
break;
case '?':
printf("unknown arg %c\n", optopt);
break;
}
}
This was I got on a getopt() man page, I understand some basic concept, but I cant put the unaccpted arguments to work. Thanks alot if someone can build this from scratch.
Thanks in advance,
fabio.
next reply other threads:[~2005-03-04 4:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-04 4:35 Fabio [this message]
2005-03-04 8:42 ` getopt() library function options Steve Graegert
2005-03-04 8:49 ` Rechberger Markus
2005-03-04 20:37 ` J.
-- strict thread matches above, loose matches on Subject: below --
2005-03-04 15:42 Huber, George K RDECOM CERDEC STCD SRI
2005-03-04 21:16 J.
2005-03-05 9:57 ` Rechberger Markus
2005-03-05 12:18 ` J.
2005-03-05 13:37 ` Rechberger Markus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1109910902.595.32.camel@0003ba16bccc \
--to=fabio@crearium.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.