0

Could someone help me understand why this code in "Caesar":

{
if (argc != 2)
   return 1 
};

generates this scolding from Check50:

:( handles lack of argv[1] \ expected output, not an exit code of 1

1 Answer 1

0

It's just as it says:

 expected output, not an exit code of 1.

Check50 is expecting to receive a print before you return 1.

As the spec says:

If your program is executed without any command-line arguments or with more than one command-line argument, your program should yell at the user and return a value of 1 (which tends to signify an error) immediately (my emphasis)

printf a message before returning 1 and you should be good.

edit Make sure you have your braces correct:

if (argc != 2)
{
    print a message
    return 1
}
7
  • You're right. Inserting a printf(Error!) solved that problem. But it also turned all of my correct encrypts from green :)s into red :(s--each with the same "expected output, not an exit code of 1" message that before only came with the argv[1] issue. I need to figure out how that printf line made the "return 1" migrate to places it hadn't been before. Sep 14, 2014 at 0:29
  • Sorry. The new error message is expected "prompt for input," not expected "output" as before. Sep 14, 2014 at 0:46
  • check your {} you might have removed one by mistake? so the program always returns 1?
    – curiouskiwi
    Sep 14, 2014 at 0:54
  • My {}s seem to balance. I've been trying gdb, and it seems not to react properly to the "if (argc != 2)" line when argc really is 2. I'll take another shot at it tomorrow. Yes, it does return 1 for each of the six (correct) encrypts. Thanks vm for your help today. Sep 14, 2014 at 1:35
  • I suspect you've put your return 1 outside the if argc !=2 loop so it executes all the time. See my edit to my answer.
    – curiouskiwi
    Sep 14, 2014 at 2:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .