From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rechberger Markus Subject: Re: getopt() library function options Date: Fri, 4 Mar 2005 09:49:07 +0100 Message-ID: References: <1109910902.595.32.camel@0003ba16bccc> Reply-To: Rechberger Markus Mime-Version: 1.0 Content-Transfer-Encoding: 7bit In-Reply-To: <1109910902.595.32.camel@0003ba16bccc> Sender: linux-c-programming-owner@vger.kernel.org List-Id: Content-Type: text/plain; charset="us-ascii" To: Fabio Cc: linux-c-programming@vger.kernel.org Hey Fabio, if(argc==1){ printf("Syntax: ....\n"); exit(1); } while ((c = getopt(argc, argv, "t:n:v")) != -1) { switch(c) { case 't': tvar = atoi(optarg); //check if optarg is numeric if not ->exit(1); break; case 'n': nvar = atoi(optarg); //same here.. break; .... Markus On Thu, 03 Mar 2005 22:35:02 -0600, Fabio 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 <> > $apstat -n <> > > 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. > > - > To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >