using getopt() more than once

Discussion in 'C Programming' started by Praveen, Dec 19, 2004.

  1. Praveen

    Praveen Guest

    Hi,

    Any one ever used getopt function more than once. Here is my example.
    I have to run a process as

    myProcess -x -y -c "-a -f myFile -o myOutput -d debugFile"

    First I have to check for -c option and use the value of this -x
    argument for next get opt.

    Any one has an experience in the same. The reply will be highly
    appreciated.

    Regards
    Praveen Kumar M
    Praveen, Dec 19, 2004
    #1
    1. Advertising

  2. Praveen

    Malcolm Guest

    "Praveen" <> wrote
    > Any one ever used getopt function more than once. Here is my example.
    > I have to run a process as
    >
    > myProcess -x -y -c "-a -f myFile -o myOutput -d debugFile"
    >

    The thing to do in these situations is first, read the documentation for the
    function, and second do a bit of exploratory programming. Just get the
    options and echo them to stdout.
    getopt() is not an ANSI function and it is years since I last used it, so I
    couldn't tell you exactly how it works.
    Malcolm, Dec 19, 2004
    #2
    1. Advertising

  3. Praveen

    Giovanni Guest

    Praveen wrote:
    > Hi,
    >
    > Any one ever used getopt function more than once. Here is my example.
    > I have to run a process as
    >
    > myProcess -x -y -c "-a -f myFile -o myOutput -d debugFile"
    >
    > First I have to check for -c option and use the value of this -x
    > argument for next get opt.
    >
    > Any one has an experience in the same. The reply will be highly
    > appreciated.
    >
    > Regards
    > Praveen Kumar M
    >


    I don't really understand what you mean. But in the manner you wrote it
    and assuming that -c is specified with an argument ("c:" in the option
    string) the string "-a -f myFile -o myOutput -d debugFile" is parsed as
    a single argument to -c. Otherwise will be parsed as a positional argument.

    I don't think you can parse it using getopt() since it is a single
    string not an array of pointers to the single word.

    Ciao
    Giovanni
    --
    A computer is like an air conditioner,
    it stops working when you open Windows.
    Registered Linux user #337974 <http://counter.li.org/>
    Giovanni, Dec 19, 2004
    #3
    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. Replies:
    1
    Views:
    388
    Jack Klein
    Jul 21, 2007
  2. Joey
    Replies:
    2
    Views:
    465
  3. Gancy
    Replies:
    4
    Views:
    172
    Rasto Levrinc
    Feb 3, 2005
  4. Steven D'Aprano
    Replies:
    0
    Views:
    90
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    80
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page