title: About CS50 pset2 vigenere
body: <p>Why my code would not skip the space and it led to wrong encryption sequence?</p>
  
  <p>When I check with an example "Hello, World!", my code counted the space also and converted to "Iekmo, Wnslc!" instead of "Iekmo, Vprke!" using the key "baz"</p>
  
  <p>Can someone explain the logic behind? Many thanks!</p>
  
  <pre><code>#include &lt;cs50.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;stdlib.h&gt;
  
  //getting user encryption key
  
  
  int main(int argc, string argv[])
  {
  
      if (argc != 2)
      {
          printf("Usage: ./vigenere keyword\n");
          return 1;
      }
      //check if all are alphabeticals
      else 
      {
             for (int i = 1; i &lt; argc; i++)
          {
              for (int j = 0; j &lt; strlen(argv[i]); j++)
              {
                  if (isalpha(argv[i][j]) == false)
                  {                
                      printf("Usage: ./vigenere keyword\n");
                      return 1;
                  }
              }
          }
      }  
  
  
      //getting plaintext divide it into each character
      string pt = get_string("plaintext: ");
  
      printf("ciphertext: ");
      //convert to ciphertext
      //C = (P + k) % 26
      for (int r = 0; r &lt; strlen(pt); r++)
      {                           
          if (isupper(pt[r]))
          {
              //making loop with j group corresponding to keyword
              int j = r % strlen(argv[1]);
              int key = tolower(argv[1][j]) - 97;
              printf("%c", (pt[r] - 65 + key) % 26 + 65);
          }
          else if (islower(pt[r]))
          {
              //making loop with j group corresponding to keyword
              int j = r % strlen(argv[1]);
              int key = tolower(argv[1][j]) - 97;
              printf("%c", (pt[r] - 97 + key) % 26 + 97);
          }
          else
          {
              printf("%c", pt[r]);
          }
  
       }            
         printf("\n");       
  
  }
  </code></pre>