On Thu, 03 Mar 2005 22:35:02 -0600, Fabio <[EMAIL PROTECTED]> wrote:
> 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;
> }
> }
>
Hi Fabio,
this is what I would try:
while ((c = getopt(argc, argv, "n:t:v")) != -1) {
switch (c)
{
case 'n':
n_flag = (int)strtoul(optarg, NULL, 0);
break;
case 't':
t_flag = (int)strtoul(optarg, NULL, 0);
break;
case 'v':
v_flag = true;
break;
default:
return -1;
}
}
It's not tested though, but hopefully points you to the right direction.
--
Kind Regards
\Steve
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming"
in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html