getopt, many parameters....
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > getopt, many parameters....




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    getopt, many parameters....  
collinm


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-25-05 11: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





[ Post a follow-up to this message ]



    Re: getopt, many parameters....  
William Ahern


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-25-05 11: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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 02:32 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register