Hi I want to write a program which takes a string and a number as input and then shifts the elements of string by given number, and also the string is always capital letters and the output should only be capital letters too
example 1 : -1 , "AB CD"
output 1 : "ZA BC"
example 2 : +3 , "ABC"
output 2 : "DEF"
I have written this code but if there is a space in my string , the program doesnt work properly
for example : -1 "AA AA"
the output is : "ZZ" But i was expecting "ZZ ZZ"
int main()
{
char str[100] = {NULL},y;
int n,x,i=0;
scanf_s("%d", &n);
scanf_s("%s", str);
while (str[i] != NULL) {
x = str[i];
if (x + n >= 65 && x + n <= 90) {
y = x + n;
str[i] = y;
}
else if (x + n < 65) {
while (x + n < 65) {
x += 26;
}
y = x + n;
str[i] = y;
}
else if (x + n > 90) {
while (x + n > 90) {
x -= 26;
}
y = x + n;
str[i] = y;
}
i++;
}
printf("%s", str);
return 0;
}