#include <stdio.h>
int main()
{
char text[1000], alpha;
int n;
printf("Please type in text:\n");
scanf("%[^\n]s", text);
printf("\nRotation number: "); // rotates letters to the right.
scanf("%d",&n);
printf("\n");
n = n % 26; // to wrap around alphabet.
int i = 0;
while (text[i] != '\0')
{
if((text[i] >= 'a' && text[i] <= 'z'))
{
alpha = text[i];
text[i] += n;
这后者字母是我不明白为什么它不工作的一部分:它的工作原理,直到凯撒密码在C:似乎无法环绕字母
if(text[i] > 'z')
{
text[i] = 'a' + (n - (26 % (alpha - 'a')));
}
字母'd'。 'f'只给出'\ 200'。
任何想法为什么我的代码不起作用?
}
i++;
}
printf("Encrypted text:\n%s", text);
return 0;
}
为什么你会做这种方式?你为什么不使用'islower()'?如此多的问题...... – EOF
我仍然学习用C语言编写代码,因此我宁愿自己编写所有代码,而不使用现有函数。 –
我不明白它能正常工作。那么问题是什么。 – ameyCU