Multiple Command line arguments in C
NickName:mjones Ask DateTime:2015-01-19T04:49:43

Multiple Command line arguments in C

I am wondering the best way to process multiple command line arguments. I have seen command line arguments done with switch and case statements like this:

while ((x = getopt(argc, argv, "bic:")) != -1){
switch (x){
  case 'b':
    //do something
    break;
  case 'i':
    //do something
    break;
  case 'c':
    //do something
    break;  
  default:
    break;
}

This works fine. However, It doesn't lend itself very well to working with multiple command line arguments. For the project I'm working on if I enter multiple arguments I would want that to be a combination of the two cases, if that makes sense. So the division between cases is a bit annoying... I guess I could make separate cases for each combination, like case: 'ib' or case: 'ibc' But is there a simpler solution?

Also, I am trying to find a solution where it doesn't matter the order of arguments entered. a.out -b -c should be the same as a.out -c -b

Copyright Notice:Content Author:「mjones」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28014668/multiple-command-line-arguments-in-c

More about “Multiple Command line arguments in C” related questions

Multiple Command line arguments in C

I am wondering the best way to process multiple command line arguments. I have seen command line arguments done with switch and case statements like this: while ((x = getopt(argc, argv, "bic:")) ...

Show Detail

Using getopt in C for command line arguments

I am working on trying to take in command line arguments. If I want to have multiple optional command line arguments how would I go about doing that? For example you can run the program in the foll...

Show Detail

Reading command line arguments for flags and files C

Hello I'm new with C and I'm trying to start this lab where the command syntax is to first list any command line flags then list one or more file names. I'm having trouble organizing how I want t...

Show Detail

C - Command line arguments as strings?

So I'm confused on how exactly command line arguments work in C... so I have these command line arguments that I'm giving: ./myclient1 MyPCName 12 7894 So I want to read argv[2] (12) as a Str...

Show Detail

Checking for command line arguments in C

I wrote this code to take input from the command line, and depending on the input, will perform a set of actions, or if the input is incorrect, throws an error. However, I also need to check if no

Show Detail

How to pass multiple arguments to Command line in VSTS

I am using Command line in VSTS in the Release pipeline. Unfortunately not sure how to pass multiple arguments like "username", "password" and "siteurl" to the command line

Show Detail

compare length of command line arguments in c

qz6_2.c can be compiled to a.exe, qz6_2.exe, or any name you prefer. When it is executed at command line, it prints a message "The longest command line argument(s): ............." to tell which arg...

Show Detail

Multiple Command Line Arguments of the same Kind

I'm confused as to how to handle multiple command line arguments of the same kind. I've seen a couple of solutions online, but they do not show what I am looking for: My command line arguments wi...

Show Detail

Multiple Command-Line Arguments - Replace Words

I've a program which takes any number of words from the command-line arguments and replaces them with the word 'CENSORED'. I finally have the program working for the first argument passed in, and I...

Show Detail

Convention for separating multiple arguments for a command line option?

The GNU project has a standard for how command line arguments should look like. However, there is no description for what to do, when an option has multiple arguments. Is there a convention for a s...

Show Detail