title: Wrapping around array causing unexpected output in c
body: <p>I would expect that the values in the array would repeat in every 3rd character but I do not understand why to out put are different if they are referencing the same index.</p>
  
  <p>Input:</p>
  
  <blockquote>
    <p>Command line argument: <code>baz</code></p>
    
    <p>User input: <code>barfoo</code></p>
    
    <p>Output: <code>caqmut</code></p>
    
    <p>Expected output: <code>caqgon</code></p>
  </blockquote>
  
  <p>Values of <code>key_number[]</code> after first for loop:</p>
  
  <pre><code>key_number[0] = 1
  key_number[1] = 0
  key_number[2] = 25
  key_number[3] = 32767
  key_number[4] = 32
  key_number[5] = 57
  </code></pre>
  
  <p>Code used:</p>
  
  <pre><code>#include &lt;cs50.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  
  int main(int argc, string argv[])
  {   
      if(argc&lt;=1)
      {
          printf("Usage: ./vigenere k");
          exit(1);
      }
      // convert command line input from string to int varible keyword
      string keyword = argv[1];
  
      //prompt user input and initialized
      printf("plaintext: ");
      string plaintext = get_string();
      printf("ciphertext: ");
  
      //create lower_case_array
      char lower_case[26] = "abcdefghijklmnopqrstuvwxyz";
  
      //create upper_case_array
      char upper_case[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
  
      //convert key from string to int[]
      //int array_length =strlen(plaintext); 
      int key_number[6]; // [array_length]
      int key_length = strlen(keyword);
      //loop though key_number for the length of plaintext
      for (int i = 0;  i &lt; (strlen(plaintext)); i++)
      {
          //if char is uppercase
          if (keyword[i] &gt;= 65 &amp;&amp; keyword[i] &lt; 91 )
          {
              key_number[i] = (keyword[i % key_length]) - 65;   
          }
          // if char is lowercase
          else if (keyword[i] &gt;= 97 &amp;&amp; keyword[i] &lt; 123)  
          {
              key_number[i] = (keyword[i % key_length]) - 97;  
          }
      }
  
      //print out letters accoring to ceasar cryptography
      for (int i = 0;  i &lt; strlen(plaintext); i++)
      {
          //branch if letter is upper case
          if (plaintext[i] &gt;= 65 &amp;&amp; plaintext[i] &lt; 91 )
          {
              printf("%c",  upper_case[((plaintext[i] - 65 + key_number[i]) % 26)]);    
          }
          //branch if letter is lower case
          else if (plaintext[i] &gt;= 97 &amp;&amp; plaintext[i] &lt; 123)
          {
              printf("%c", lower_case[((plaintext[i] - 97 + key_number[i]) % 26)]);
          }
          //branch if any other character
          else
          {
              printf("%c", plaintext[i]);
          }
      }
      printf("\n");
  }
  </code></pre>