Implementing Caesar Cipher in C I am trying to implement a "Caeser cipher" to every lower case character in a string, by using a number to control the amount of character rotation. Here is an algorithm that I came up with. Can you please review and give me some feedback?

#include &lt;stdio.h&gt;
int main()
{
    char string4[80];
    int  rotatorN;

    printf("Enter String: ");
    gets(string4);
    printf("Enter Number: ");
    scanf("%i", &amp;rotatorN);

    int n = 0, rotateSwap = 0;

    int i;
    for(i=0; string4[i] != '\0'; i++)
     {
          if(string4[i] &gt;='a' &amp;&amp; string4[i] &lt;='z')
             {
                n = 'z' - string4[i];
                if( rotatorN &gt; n )
                 {
                    rotateSwap = rotatorN - n - 1;
                    string4[i] = 'a';
                    string4[i] += rotateSwap;
                  }  
               else
                string4[i] += rotatorN;


               }
       }

      int j;
      for(j = 0; string4[j] !='\0'; j++)
        {
             printf("%c", string4[j]);
        }

        printf("\n");

        return 0;
}
You should never use gets() to read keyboard input, ever. Use fgets(), where you specify the max size of the buffer. That way, you are protecting yourself from somebody hacking your code.

You don't check input values. It is good practice to not assume a benevolent keyboard user, so, for instance, when a user enters rotatorN = -12128, you get all kinds of interesting behavior in your program.

Using scanf for input is hard to get right and therefore error-prone. Instead, use fgets for all input and then use sscanf to get the contents.

Check the calculated value for rotateSwap so that it falls within the expected range.