ROT13代码中的错误(C)

ROT13代码中的错误(C),c,rot13,C,Rot13,我的程序应该接收一个字符,如果它是一个字母,则使用ROT13对其进行编码,否则保持不变,然后打印结果 下面的代码适用于所有小写字母和大写字母A-M,但不适用于大写字母N-Z和其他符号/数字。感谢您的帮助:) #包括 #包括 #包括 #定义真1 #定义FALSE 0 #定义上止点65 #定义上端90 #定义下_起点97 #定义下端122 #定义上_MID 77 #定义下_MID 109 无效测试代码(void);int是有效的(char-cipherChar);字符编码(字符字母); int ma

我的程序应该接收一个字符,如果它是一个字母,则使用ROT13对其进行编码,否则保持不变,然后打印结果

下面的代码适用于所有小写字母和大写字母A-M,但不适用于大写字母N-Z和其他符号/数字。感谢您的帮助:)

#包括
#包括
#包括
#定义真1
#定义FALSE 0
#定义上止点65
#定义上端90
#定义下_起点97
#定义下端122
#定义上_MID 77
#定义下_MID 109
无效测试代码(void);int是有效的(char-cipherChar);字符编码(字符字母);
int main(int argc,char*argv[]){
字符-密码字符;
scanf(“%c”、&cipherChar);
if(isValid(cipherChar)==TRUE){
printf(“%c”,编码(cipherChar));
}else if(isValid(cipherChar)=FALSE){
printf(“%c”,cipherChar);
}
返回退出成功;
}
int是有效的(char-cipherChar){
int有效;
如果((cipherChar>=上限\u开始)&&
(cipherChar=下部启动)&&
(cipherChar通常不会影响除
[A-Za-z]
以外的字符,因此我建议忽略这些字符。除非您也有理由旋转它们。例如,有时0-9用ROT5处理

在任何情况下,您的
if
语句和子句
(字母=LOWER\u START和字母LOWER\u END){
字母-=13;
}
}

在您的encode函数中,我只需要使用mod运算符(
%
)。简单多了。如果您可以访问C99编译器(有几个),您可以包含
#包含
,而不是使用
int
,您可以使用
bool
,而不是
TRUE
FALSE
您可以使用标准
TRUE
FALSE
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

#define TRUE 1
#define FALSE 0

#define UPPER_START 65
#define UPPER_END 90
#define LOWER_START 97
#define LOWER_END 122

#define UPPER_MID 77
#define LOWER_MID 109


void testEncode (void); int isValid (char cipherChar); char encode (char letter);

int main (int argc, char* argv[]) {

    char cipherChar;

    scanf("%c", &cipherChar);
    if (isValid(cipherChar) == TRUE) {
        printf("%c", encode (cipherChar));
    } else if (isValid(cipherChar) == FALSE) {
       printf("%c", cipherChar);
    }
       return EXIT_SUCCESS;

}

int isValid (char cipherChar) {

    int valid;

    if ((cipherChar >= UPPER_START) &&
        (cipherChar <= UPPER_END)) {
        valid = TRUE;
    } else if ((cipherChar >= LOWER_START) &&
            (cipherChar <= LOWER_END)) {
        valid = TRUE;
    } else {
        valid = FALSE;
    }

    return valid;
}

char encode (char letter) {

    if ((letter <= UPPER_MID) || (letter <= LOWER_MID)) {
        letter = letter + 13;
    } else {
        letter = (letter - 13);
    }

    return letter;
}
if (letter >= UPPER_START && letter <= UPPER_END) {
    letter = letter + 13;

    if (letter > UPPER_END) {
        letter -= 13;
    }
} else if (letter >= LOWER_START && letter <= LOWER_END) {
    letter = (letter + 13);

    if (letter > LOWER_END) {
        letter -= 13;
    }
}