So far I've only gotten to the part where the code should check to see if the key is only digits.

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

int main(int argc, string argv[])
       if(argc != 2){
           printf("Use ./caesar key\n");
              return 1;

    string s = argv[1];

        for (int i = 0, n = strlen(s); i < n; i++){

            if (isdigit (s[i]) != true){
                printf("Numbers only \n");
                return 1;


However, it outputs "Numbers only" regardless of what key is entered, even if the key provided is completely numerical.


Review the man page for isdigit, specifically the return value.

Return Value

The values returned are nonzero if the character c falls into the tested class, and a zero value if not.

You are going to need to "reword" this test if (isdigit (s[i]) != true). The function does not return a boolean; it returns a 0 if the character is not 0 through 9.

You must log in to answer this question.

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