[cs631apue] overriding the no argument condition in getopt

Jason Ajmo jajmo at stevens.edu
Fri Oct 13 13:19:07 EDT 2017


Yeah, for the optstring the colon means you need to specify something with
that individual switch, which doesn't apply to this project since the
file/folder operands apply to the program itself, not the individual
switches.

If you check out the manpage for getopt(3), it has examples of how the
colon works.

On Fri, Oct 13, 2017 at 1:14 PM mseaton <mseaton at stevens.edu> wrote:

> 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
>
-- 
Jason Ajmo
Stevens Institute of Technology
B.S. Cybersecurity '17
M.S. Computer Science '18
0x56FA3123
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20171013/c20a31fc/attachment.html>


More information about the cs631apue mailing list