Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Command Line Option Validation |
| Date | 2014-04-15 12:36 +1200 |
| Message-ID | <br3d7hF3g7rU4@mid.individual.net> (permalink) |
| References | <e4fc3d3a-5f39-4ecb-ba66-85e188083e19@googlegroups.com> |
willmann817@gmail.com wrote:
> when the user runs my program from the command line I require them to
> type
>
> myProgram -k <some_value>
>
> <some_value> needs to be a positive integer between 1 and 100. How
> do I assure they do not type in a string or something like that.
> Here is what I have so far but I am not sure what to do from here?
>
> int main(int argc, char *argv []){
> //Getting command line arguments using getopt.
> while((ch = getopt(argc, argv, "k:m:s")) != EOF){
> switch(ch){
> case "k":
> if
Use strtol to parse the the appropriate argv value and check the result.
--
Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Command Line Option Validation willmann817@gmail.com - 2014-04-14 17:08 -0700 Re: Command Line Option Validation Ian Collins <ian-news@hotmail.com> - 2014-04-15 12:36 +1200 Re: Command Line Option Validation Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-04-15 00:58 -0700
csiph-web