Author: Stan Eisenstat
Subject: Re: [Cs223] Question Regarding Command Line Args
Date: Wednesday, 12 Feb 2020, 08:18:43
> Message Posted By: Unknown > > I was testing your Binpack: > % ./Binpack 10 4 -opt -ff 44 abcde > > and noticed that it prints > -opt 1 > -ff 1 > 44 invalid flag > > I reread the specifications and it states that the given command-line > arguments should be % ./Binpack BIN_SIZE [ITEM_SIZE]* [-opt | -ff | -bf | > -ffd | -bfd]* > > The spec also states that [-opt | -ff | -bf | -ffd | -bfd]* should be a > sequence of zero or more flags, each either -opt or -ff or -bf or -ffd or > -bfd. It also states that Note that the notation above implies that all item sizes must *precede* the first flag. which explains the behavior above: Since -opt is a flag, 44 and abcde cannot be item sizes and thus must be invalid flags. ===== > Clearly, 44 and abcde are improper flags. Shouldn't the executable quit > instead of process anything? ... The question is whether an invalid flag should be detected before any flag is executed, or only when it is encountered in the left to right order on the command line. This is not specified, and the final test script will accept either behavior. --Stan-PREV INDEX NEXT