#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;
これは、なぜ機能しないのか理解できない部分です。
if(text[i] > 'z')
{
text[i] = 'a' + (n - (26 % (alpha - 'a')));
}
文字「d」まで機能します。'f' は単に '\200' を返します。
私のコードが機能しない理由についてのアイデアはありますか?
}
i++;
}
printf("Encrypted text:\n%s", text);
return 0;
}