[cs631apue] overriding the no argument condition in getopt

mseaton mseaton at stevens.edu
Fri Oct 13 13:14:38 EDT 2017


Hi Jason,

Yeah, I am referring to the opstring of getopt(3) as well the operands.
For example: (ls -a) and (ls -a DIRNAME) should both work. getopt(3) 
says that you must place a ":" after an option if it should return an 
argument. By doing this, ls -a won't work.
I guess you are saying I should not place a ":" after any of the command 
options. In which case I won't have to worry about optarg which was what 
I used to determine if an argument was entered or not.

Thanks.
Marlon
On 10/13/2017 11:15 AM, Jason Ajmo wrote:
> I'm not sure if you're referring to the optstring for getopt(3) or the
> program operands, but neither are required. You should specify your
> optstring in a way that won't error if no options are supplied.
> 
> getopt(3) doesn't process the operands; just the command line
> switches. That's why, after getopt(3) is done, you need to decrement
> argc, and increment argv to get the proper starting point of the
> operands.
> 
> On Fri, Oct 13, 2017 at 11:11 AM mseaton <mseaton at stevens.edu> wrote:
> 
>> Hello,
>> 
>> I understand setting opterr to zero means that getopt will not
>> report an
>> error if no argument is entered, but our options must be able to
>> work in
>> both cases, however it still does not allow the program to continue
>> if
>> no argument is entered.
>> 
>> Is there something I am missing?
>> Thanks
>> _______________________________________________
>> cs631apue mailing list
>> cs631apue at lists.stevens.edu
>> https://lists.stevens.edu/mailman/listinfo/cs631apue [1]
> 
> --
> 
> Jason Ajmo
> Stevens Institute of Technology
> B.S. Cybersecurity '17
> M.S. Computer Science '18
> 0x56FA3123
> 
> Links:
> ------
> [1] https://lists.stevens.edu/mailman/listinfo/cs631apue


More information about the cs631apue mailing list