title: What is happening to the printf function?
body: <p>I am attempting to write the substitution program here <a href="https://cs50.harvard.edu/x/2022/psets/2/substitution/" rel="nofollow noreferrer">https://cs50.harvard.edu/x/2022/psets/2/substitution/</a></p>
  <p>here is my code:</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;math.h&gt;
  
  int main(int argc, string argv[1])
  {
      if (argc &gt; 2 || argc &lt; 2){
          printf(&quot;Plz 1 word in command \n&quot;);
          return 1;
      }
      int sum = 0;
      string arg1 = argv[1];
  
  
      //test
      for (int i = 0; i &lt; strlen(arg1); i++){
          if (isalpha(arg1[i]) == 0){
              printf(&quot;plz only alphabet character \n&quot;);
              return 1;
          }}
      // convert all key to upper
      for (int i = 0; i &lt; strlen(arg1); i++){
          arg1[i] = toupper(arg1[i]);
       }
      for (int i = 0; i &lt; strlen(arg1); i++){
            sum = sum + (int)(arg1[i]);
      }
      if (strlen(arg1) != 26){
          printf(&quot;Plz input 26 char \n&quot;);
          return 1;
      } else if (sum != 2015){printf(&quot;no oveerlapping letter plz \n&quot;);
      return 1; }
      //test finish
      string al = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;;
      string pt = get_string(&quot;plaintext: &quot;);
      char pt1[strlen(pt)]; 
      char cp[strlen(pt)]; 
      // all plain text to upper
      for (int i = 0; i &lt; strlen(pt); i++){
          pt1[i]=toupper(pt[i]);
      }
      //scan
      for (int a = 0; a &lt; strlen(pt); a++){
          char b = pt1[a];
          for (int i = 0; i &lt; strlen(al); i++){
               if ( al[i] == b){
                     cp[a] = arg1[i];
                     break;
               } else {
                  cp[a] = b;
               }
          }
      //case preserve
        if (islower(pt[a])){
           cp[a] = tolower(cp[a]);
      }} 
  
         printf(&quot;ciphertext: %s \n&quot;, cp);
         return 0;
  }
  </code></pre>
  <p>when i type in the key YTNSHKVEFXRBAUQZCLWDMIPGJO and then type &quot;hello!1 lmao&quot; as plaintext, here is what i receive</p>
  <pre><code>substitution/ $ ./substitution YTNSHKVEFXRBAUQZCLWDMIPGJO
  plaintext: hello!1 lmao
  ciphertext: ehbbq!1 bayq� 
  </code></pre>
  <p>it should only show ehbbq!1 bayq but it is showing more letter than i intended,
  there might be other letter or simbol after &quot;bayq&quot;, can someone explain to me what is going on and why there are additional text in my output?</p>