I am working on a code in which I shift each letter by one place, so (a) becomes (b) and (b) becomes (c) and so on. So far I managed to do that, but I am confronting a problem wrapping around the capital letter (Z) to (A). I can't seem to get the logic how to do that. Any help would be appreciated. Thanks a lot.
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
int main(void)
{
//prompt the user to type in a text.
string p = get_string("plaintext: ");
//create a variable to refer to the length of the string.
int n = strlen(p);
for (int i = 0; i < n; i++)
{
//check if all chars (i) in the string (p) are alphabetical then increment i by 1.
if (isalpha(p[i]))
p[i]++;
{
//check if i has gone beyond the letter (z) and (Z).
if ((p[i] > 'z') && (p[i] > 'Z'))
{
//if so then subtract 26 letter after z or Z to get back to a or A.
p[i] = p[i] - 26;
}
}
printf("%c", p[i]);
}
printf("\n");
}