|
Home > Archive > Unix Programming > July 2005 > getopt, many parameters....
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
getopt, many parameters....
|
|
| collinm 2005-07-25, 6:07 pm |
| hi
i would like to be able to do:
-t 18 -f a1 a2 a3....
i don't know how much parameter there is for f....
are there a way to do that?
the code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main (int argc, char **argv)
{
int c;
int timer=0;
int cptTime=0;
char *ifile;
int index;
extern char *optarg;
extern int optind, optopt;
printf("argc: %d\n", argc);
while ((c = getopt(argc, argv, "t:f")) != -1) {
switch(c) {
case 't':
timer=1;
cptTime = atoi(optarg);
break;
case 'f':
ifile = optarg;
break;
}
}
if(timer==1)
while(1==1)
{
}
for (index = optind; index < argc; index++)
printf ("Non-option argument %s\n", argv[index]);
return 0;
}
thanks
| |
| William Ahern 2005-07-25, 6:07 pm |
| collinm <collinm@laboiteaprog.com> wrote:
> hi
>
> i would like to be able to do:
>
> -t 18 -f a1 a2 a3....
Standard convention is to use the form:
-t 18 -f a1 -f a2 -f a3
Or
-t 18 -f "a1 a2 a3"
Though the latter means you have to parse it yourself.
Otherwise, I don't think getopt() will work for you unless '-f' will always
be the last argument given--so you know you could traverse the remaining
indices in argv. But, that's quite ugly and it gets worse from there.
- Bill
|
|
|
|
|