私のコードが AZ 0-9 の文字を含まない文字列を受け入れないのはなぜですか? これをたとえば「aaaaa[[[[[[」」のように暗号化すると、エラーが発生します。スペースなども受け入れ、az、AZ、0-9 以外のものをスキップできるようにコードが必要です。
私の最後のelseステートメントがうまくいかないのはなぜですか?
例えば:
"a a" shift 1
する必要があります
"b b"
私のコード:
#include <stdio.h>
int main (){
char word[20];
int rotx;
printf("enter string\n");
scanf("%s", word);
printf("enter rotations\n");
scanf("%d", &rotx);
encrypt(word, rotx);
return 0;
}
void encrypt (char word[], int rotx){
int w = strlen(word) - 1;
int i = 0;
for ( ; i <= w; i++)
if ((word[i] + rotx) >= 65 && (word[i] + rotx) <=90)
{
word[i] += (rotx);
}
else if ((word[i] + rotx) >= 97 && (word[i] + rotx) <=122)
{
word[i] += (rotx);
}
else if ((word[i] + rotx) >= 48 && (word[i] +rotx) <= 57)
{
word[i] += (rotx);
}
else if ((word[i] + rotx) > 90 && (word[i]+rotx) <97)
{
word[i] = 64 + (rotx - (90-word[i]));
}
else if ((word[i] + rotx) > 122)
{
word[i] = 96 + (rotx - (122-word[i]));
}
else
{
continue;
}
}