title: How to shift chars w/pointers
body: <p>I'm trying to write a function in C which shifts each letter of a <code>char *</code>, so <code>'a'</code> becomes <code>'z'</code> and <code>'b'</code> becomes <code>'y'</code>. In the <code>if</code> statements below, it's my understanding that <code>(*p - 'a')</code> is the letter <code>p</code> points to, but I'm not sure how to shift the char to achieve the desired result. Any guidance would be greatly appreciated. </p>
  
  <pre><code>void encode(char *s1, char *s2) {
      char *p, *q;
  
      q = s2;
      for (p = s1; p &lt; p + p[STR_LEN]; p++, q++) {
          if (*p &gt;= 'a' &amp;&amp; *p &lt;= 'z') {
              *q = (*p - 'a');
          } else
          if (*p &gt;= 'A' &amp;&amp; *p &lt;= 'Z') {
              *q = (*p - 'A');
          }
      }
  }
  </code></pre>
  
  <p><strong>EDIT</strong>
  Thanks for all the help! It looks like the best algorithm was *q = 'A' + 'Z' - (*p), but for some reason it's only encoding the first and second word, with this ▒ as a space. The problem is obviously the rest of my code so I'll get to work. Thanks again!</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>I had to add the code below to account for a space character. Thanks again!</p>
  
  <pre><code>else if (*p == ' ')
              {
                      *q = ' ';
              }
  </code></pre>