title: How can I exclude non-numeric keys? CS50 Caesar Pset2
body: <p>I'm doing the CS50 Caesar problem and for the most part, my code works. I am not able to pass one of the check50 tests - my code does not handle non-numeric keys, and it timed out while waiting for the program to exit.</p>
  
  <p>I have tried utilizing isdigit but it does not seem to work.</p>
  
  <p>The check50 tests results copied pasted below:</p>
  
  <pre><code>:) 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 key
  :( handles non-numeric key
      timed out while waiting for program to exit
  :) handles too many arguments
  </code></pre>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;cs50.h&gt;
  #include &lt;math.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main (int argc, string argv[])
  {
  
  
      if (argc == 2 &amp;&amp; (isdigit(argv[1] !=0))
      {
  
  
          int k = atoi (argv[1]); // convert string to int
          string s = get_string ("plaintext: "); // obtain text
  
          printf("ciphertext: ");
          for (int i = 0; i &lt; strlen(s); i++) // text loop
          {
              if (s[i] &gt;= 'a' &amp;&amp; s[i] &lt;= 'z')
              {
                  printf("%c", 'a' + ((s[i] - 'a') + k) % 26);
              }
  
              else if (s[i] &gt;= 'A' &amp;&amp; s[i] &lt;= 'Z')
              {
                  printf("%c", 'A' + ((s[i] - 'A') + k) % 26);
              }
  
              else
              {
                  printf("%c", s[i]);
              }
  
  
          }
  
  
          printf("\n");
          return 0;
      }
  
  
  
      else
      {
          printf("./caesar key\n");
      }
  
      return 1;
  }
  
  </code></pre>