Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I'm new here so I'm not sure if my question is in the correct category. I'm having problems with getopt(). Here's what I'm doing. I'm calling getopt() from C. ...
  1. #1
    Just Joined!
    Join Date
    Nov 2011
    Posts
    2

    Using getopt()

    Hi,
    I'm new here so I'm not sure if my question is in the correct category. I'm having problems with getopt().
    Here's what I'm doing. I'm calling getopt() from C.
    I'm invoking my C program like this: myprog -a -b -c

    And in C:
    while ((c = getopt (argc, argv, "a:b:c")) != -1) { ... }

    The idea is to have arguments for all the options.
    What happens though is that if I leave off the argument for option -a getopt thinks -b is the argument for option -a and getopt doesn't return an error.
    Is this how getopt should work? I thought getopt would recognise that -b is an option.

    Thanks in advance for any help.

  2. #2
    Linux Guru
    Join Date
    May 2011
    Posts
    1,813
    A poster at stackoverflow seems to talk about your problem, maybe you can get one of the posted solutions to work for you.

  3. #3
    Just Joined!
    Join Date
    Nov 2011
    Posts
    2
    Thanks atreyu, the link you posted solved my problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •