0

Here's what I'm getting back - thoughts on how to fix this?

jharvard@appliance (~/Dropbox/pset2): check50 2014/x/pset2/caesar caesar.c
:) caesar.c exists
:) caesar.c compiles
:) encrypts "a" as "b" using 1 as key
:) encrypts "barfoo" as "yxocll" using 23 as key
:) encrypts "BARFOO" as "EDUIRR" using 3 as key
:) encrypts "BaRFoo" as "FeVJss" using 4 as key
:) encrypts "barfoo" as "onesbb" using 65 as key
:) encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key
:( handles lack of argv[1]
\ expected output, not standard error of "/opt/sandbox50/bin/run.sh: line 31: 107..." https://sandbox.cs50.net/checks/a949d615c42143f695f538b06d43fb23

1 Answer 1

3

Your program is not handling the case where the user does not provide a key.

The array argv contains the command line arguments used to run the program. For example, the command "./caesar yxocll" will put put "./ceasar" into argv[0] and "yxocll" into argv[1]. A lack of argv[1] means that the program was run with the command "./caesar" as there is no second argument.

Check50 expects the program to print an error message and return a nonzero integer when argc is less than 2, which indicates that no key has been given.

2
  • Yep that's what I thought, except that it is returning the correct error message when I have argc > 2 or argc that is non-numerical. it seems that the error only occurs when there is no argv[1] but I thought I controlled for that in my code via the "argc != 2" text - check out the code below: while (argc != 2 || key < 1) { printf("That is incorrect. Please start over from the command line and enter a Key that is a positive integer\n"); return 1; }
    – jsa724
    Nov 24, 2014 at 22:25
  • @jsa724, from looking at your code, it appears you have already called 'int key = atoi(argv[1]);' before the check. The problem with this is that trying to access the non-existent argv[1] will cause a segfault. Try doing things in this order: check # of arguments, read the value of key, check the value of key.
    – Paul
    Nov 27, 2014 at 15:10

You must log in to answer this question.

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