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.
...
- 11-04-2011 #1Just 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.
- 11-04-2011 #2Linux 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.
- 11-04-2011 #3Just Joined!
- Join Date
- Nov 2011
- Posts
- 2
Thanks atreyu, the link you posted solved my problem.


Reply With Quote
