it is about pset 2 caesar.c

Question 1: Do I need to consider the case when the user input something after ./caesar (argv [1]) instead of an integer?

Example: ./ caesar a

Question 2: I found out the following hints from the cs50 website:

$ ./caesar Usage: ./caesar k $ ./caesar 1 2 3 4 5 Usage: ./caesar k

Is that mean I have to printf("Usage: ./caesar k\n") and to return 0; when argc equal to 2?

1 Answer 1

  1. Quoting the problem specification:
    • You can assume that, if a user does provide a command-line argument, it will be a non-negative integer (e.g., 1). No need to check that it’s indeed numeric.
  2. Same source:
    • If your program is executed without any command-line arguments or with more than one command-line argument, your program should print an error message of your choice (with printf) and return from main a value of 1 (which tends to signify an error) immediately.
  • So, it that mean I need not to printf "Usage: ./caesar k\n" ? Is that mean I can printf("error\n) or somethings like that?
    – Christy Ng
    Jan 24, 2018 at 3:55
  • If argc is not 2 (corresponding to one command-line argument), complain to the user (a hint on correct usage is much nicer from the user's perspective) and return 1.
    – Blauelf
    Jan 24, 2018 at 6:09

You must log in to answer this question.

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