#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