C旋转字符串程序


#include <stdio.h>

int main()
{
int rotation, i=0;
char str[80]={0}; 
printf("Enter Text: ");
scanf("%[^n]", str); 
printf(""");
printf("Enter Rotation: ");
scanf("%i", &rotation);
while(str[i]) 
    {
        if (str[i] >= 'a' && str[i] <= 'z')
        printf("%cn", 'a' + (str[i] - 'a' + rotation)%26); 
        else    
        printf("%cn", str[i]);
        i++;    
    }
return 0;
}

很难理解这条代码(printf("%c n",'a' (str [i] - 'a' rotation)%26);)

任何人都可以快速写一个简短的解释,这将帮助我

该程序正在根据输入的数字将用户的输入文本和每个字符旋转通过字母进行。它是由于ASCII表而起作用的。

所讨论的行将用户输入的字符取消 'a'(等于ASCII中的91)的字符,然后在rotation因子中添加,然后在结果上执行modulo 26(再次在字母内有多少个字符?)确保结果仍然是小写字符。

我敢打赌,您可以找到一个打破此程序的好方法:)

最新更新