title: I am new to coding and stuck on a cipher problem from cs50
body: <p>I am new and still getting the hang of things so help would be much appreciated.
  Here is the basic problem:
  A key, for example, might be the string NQXPOMAFTRHLZGECYJIUWSKDVB. This 26-character key means that A (the first letter of the alphabet) should be converted into N (the first character of the key), B (the second letter of the alphabet) should be converted into Q (the second character of the key), and so forth.</p>
  <p>A message like HELLO, then, would be encrypted as FOLLE, replacing each of the letters according to the mapping determined by the key.</p>
  <p>Here is my attempt:</p>
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  char convert(char c, char *p);
  int main(int argc, char *argv[]){
      //argv[1] has the key.
      printf(&quot;THE KEY:\n%s\n&quot;,argv[1]);
      char *ptr;
      ptr=(char*)malloc(50);
      printf(&quot;Enter the string to be encoded:\n&quot;);
      scanf(&quot;%s&quot;,ptr);
      printf(&quot;%s\n&quot;,ptr);
      char ch;
      for(int i=0;i&lt;strlen(ptr);i++)
      {
          ch=*ptr;
          ch=convert(ch,&amp;argv[1][0]);
          *ptr=ch;
          ptr++;
      }
      printf(&quot;Encoded string is:\n&quot;);
      printf(&quot;%s&quot;,ptr);
      return 0;
  }
  
  char convert(char c, char *p)
  {
      char x='a';
      char y='A';
      for(int i=0;i&lt;=25;i++)
      {
          if(x==c||y==c)
          {
              return (*p);
          }
          ++x;
          ++y;
          ++p;
      }
  }
  </code></pre>
  <p>HERE IS THE OUTPUT:</p>
  <pre><code> PS C:\Users\Shreyansh\Desktop\CS TUTORIALS\CS50&gt; .\06_Cipher.exe NQXPOMAFTRHLZGECYJIUWSKDVB
  THE KEY:
  NQXPOMAFTRHLZGECYJIUWSKDVB
  Enter the string to be encoded:
  HELLO
  HELLO
  Encoded string is:
  LO
  </code></pre>
  <p>For some reason the output stops there. Please help. I don't know what I am doing wrong.</p>