Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't do range tests like this:</p> <pre><code>'a' &lt;= msg[i] &lt;= 'z' </code></pre> <p>This evaluates as <code>'a' &lt;= msg[i]</code> becomes true or false (1 or 0), which is always less than <code>'z'</code>.</p> <p>So to start you need:</p> <pre><code>( msg[i] &gt;= 'a' &amp;&amp; msg[i] &lt;= 'z' || msg[i] &gt;= 'A' &amp;&amp; msg[i] &lt;= 'Z' ) </code></pre> <p>Now, you have put this condition on your loop, so it will terminate as soon as you encounter a special character. If you want to have different behaviour for letters, check them inside the loop:</p> <pre><code>for( i = 0; msg[i] != 0; i++ ) { if( msg[i] &gt;= 'a' &amp;&amp; msg[i] &lt;= 'z' || msg[i] &gt;= 'A' &amp;&amp; msg[i] &lt;= 'Z' ) { encrypted[i] = msg[i] + key; } else { encrypted[i] = msg[i]; } } </code></pre> <p>Now the second part of your question. You appear to want to rotate your letters. Try this:</p> <pre><code>// Sanity -- to avoid overflowing `char` key %= 26; while( key &lt; 0 ) key += 26; for( i = 0; msg[i] != 0; i++ ) { if( msg[i] &gt;= 'a' &amp;&amp; msg[i] &lt;= 'z' ) { encrypted[i] = 'a' + ((msg[i]-'a' + key) % 26); } else if( msg[i] &gt;= 'A' &amp;&amp; msg[i] &lt;= 'Z' ) { encrypted[i] = 'A' + ((msg[i]-'A' + key) % 26); } else { encrypted[i] = msg[i]; } } </code></pre> <p>If you don't want non-letters in the encrypted string at all, then make another index:</p> <pre><code>int e = 0; encrypted[e++] = etc; // Only when you want to add something to the string. </code></pre> <p>And don't forget after the loop:</p> <pre><code>encrypted[e] = 0; // terminate string. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload