getopt help required

Discussion in 'C Programming' started by Rishi, Feb 18, 2008.

  1. Rishi

    Rishi Guest

    suppose i have a program in which there are two arguements 'a' and 'b'

    the program is such that i will work iff
    -> either 'a' or 'b' is present as an option to it
    -> both 'a' and 'b' cant be present sameltaneously
    -> either of the two should be there

    I want to know is there any way in the function getopt or getopt_long
    that can help me in doing this


    Thanks in advance
    Rishi, Feb 18, 2008
    #1
    1. Advertising

  2. Rishi

    Daniel Kraft Guest

    Rishi wrote:
    > suppose i have a program in which there are two arguements 'a' and 'b'
    >
    > the program is such that i will work iff
    > -> either 'a' or 'b' is present as an option to it
    > -> both 'a' and 'b' cant be present sameltaneously
    > -> either of the two should be there
    >
    > I want to know is there any way in the function getopt or getopt_long
    > that can help me in doing this


    Well, I'm not sure this is on topic here (comp.unix.programmer might be
    better), but AFAIK getopt can set a boolean flag on encountering an
    option; just do this, and check afterwards your conditions against the
    two flag-variables and take appropriate action.

    Daniel

    --
    Done: Bar-Sam-Val-Wiz, Dwa-Elf-Hum-Orc, Cha-Law, Fem-Mal
    Underway: Ran-Gno-Neu-Fem
    To go: Arc-Cav-Hea-Kni-Mon-Pri-Rog-Tou
    Daniel Kraft, Feb 18, 2008
    #2
    1. Advertising

  3. In article <>,
    Rishi <> wrote:
    >suppose i have a program in which there are two arguements 'a' and 'b'
    >
    >the program is such that i will work iff
    >-> either 'a' or 'b' is present as an option to it
    >-> both 'a' and 'b' cant be present sameltaneously
    >-> either of the two should be there
    >
    >I want to know is there any way in the function getopt or getopt_long
    >that can help me in doing this
    >
    >
    >Thanks in advance


    Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

    --
    Useful clc-related links:

    http://en.wikipedia.org/wiki/Aspergers
    http://en.wikipedia.org/wiki/Clique
    http://en.wikipedia.org/wiki/C_programming_language
    Kenny McCormack, Feb 18, 2008
    #3
  4. "Rishi" <> wrote in message
    news:...
    > suppose i have a program in which there are two arguements 'a' and 'b'
    >
    > the program is such that i will work iff
    > -> either 'a' or 'b' is present as an option to it
    > -> both 'a' and 'b' cant be present sameltaneously
    > -> either of the two should be there
    >
    > I want to know is there any way in the function getopt or getopt_long
    > that can help me in doing this
    >

    I've got an options parser on my website that may do what you want.

    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
    Malcolm McLean, Feb 18, 2008
    #4
  5. Rishi

    Mark Bluemel Guest

    Rishi wrote:
    > suppose i have a program in which there are two arguements 'a' and 'b'
    >
    > the program is such that i will work iff
    > -> either 'a' or 'b' is present as an option to it
    > -> both 'a' and 'b' cant be present sameltaneously
    > -> either of the two should be there
    >
    > I want to know is there any way in the function getopt or getopt_long
    > that can help me in doing this


    getopt is not part of the language, it's a Posix library function, so
    it's not really on-topic here.


    Depending on whether you really want the Posix version or the GNU
    variant, you'd need to look in slightly different places.

    As far as I can see from a brief examination, neither provide an easy
    way of making options/arguments mutually exclusive.
    Mark Bluemel, Feb 18, 2008
    #5
  6. Rishi <> writes:
    > suppose i have a program in which there are two arguements 'a' and 'b'
    >
    > the program is such that i will work iff
    > -> either 'a' or 'b' is present as an option to it
    > -> both 'a' and 'b' cant be present sameltaneously
    > -> either of the two should be there
    >
    > I want to know is there any way in the function getopt or getopt_long
    > that can help me in doing this


    Ask in comp.unix.programmer.

    --
    Keith Thompson (The_Other_Keith) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Feb 18, 2008
    #6
  7. On 18 Feb 2008 at 17:21, Keith Thompson wrote:
    > Rishi <> writes:
    >> suppose i have a program in which there are two arguements 'a' and 'b'
    >>
    >> the program is such that i will work iff
    >> -> either 'a' or 'b' is present as an option to it
    >> -> both 'a' and 'b' cant be present sameltaneously
    >> -> either of the two should be there
    >>
    >> I want to know is there any way in the function getopt or getopt_long
    >> that can help me in doing this

    >
    > Ask in comp.unix.programmer.


    Ah, how the warmth and friendliness shine from every one of Kiki's
    words!
    Antoninus Twink, Feb 18, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arvind Kumar

    Problem with Getopt

    Arvind Kumar, Nov 3, 2003, in forum: Perl
    Replies:
    1
    Views:
    558
    Jim Gibson
    Nov 3, 2003
  2. Just D.
    Replies:
    0
    Views:
    435
    Just D.
    Mar 10, 2006
  3. dima
    Replies:
    9
    Views:
    683
    llewelly
    Sep 5, 2003
  4. Ramiro Rodriguez

    getopt

    Ramiro Rodriguez, Oct 14, 2003, in forum: C++
    Replies:
    6
    Views:
    3,989
    Lorenzo Bettini
    Oct 17, 2003
  5. Stan Brown

    Help using Getopt::Mixed

    Stan Brown, Nov 2, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    133
    Stan Brown
    Nov 2, 2003
Loading...

Share This Page