I have started working on Caesar and I am stuck with how to repromt user for a command line argument incase they input some wrong values.

Here is the code i wrote and I can't find any apparent errors

#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <ctype.h>

int main (int argc, string argv[])
        printf("Usage: ./caesar key");
        return 1;
   while (argc != 2 || !isdigit(argv[1]));

I am getting the printf message even when the input values are correct. What exactly is going wrong here?

  • 1
    So what your looping is doing, is printing "Usage: bla bla" when there's more or less than 2 arguments AND the first digit of the second argument is not a number. If the user input ./caesar 2a -> you have two arguments and the FIRST digit of Argv[1] is a number. Im guessing that this is your mistake Oct 5, 2020 at 15:46
  • I have 2 queries isn't it saying OR as i am using || and not &&? Also isn't Argv[1] the entire string? so in your example 2a would be the string right? and isdigit would output false as it is not a digit? Am I making some mistake here @leonardoantunes Oct 5, 2020 at 15:54
  • 1
    The first one, i confused the signs. About the second one perhapes this help you -> [ geeksforgeeks.org/isalpha-isdigit-functions-c-example ] Oct 6, 2020 at 16:35
  • thanks :) @leonardoantunes Oct 6, 2020 at 18:29
  • 1
    you're welcome, good luck with your studies !!! Oct 7, 2020 at 0:45

2 Answers 2


Perhaps a review of the class material on command line arguments is in order?



You can't reprompt a user for command line arguments. You will have to exit the program after printing the usage.

You must log in to answer this question.

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