我的 CS50 凯撒问题代码有什么问题?

What is wrong with my code for CS50 Caesar problem?

本题旨在应用凯撒密码。目标是加密用户定义的消息。该问题要求我们使用命令提示符获取密钥。获得消息和密钥后,我们必须通过密钥移动来加密每个字符。例如如果密钥是 1 那么 A - B 和 b - c 和 z - a,如果密钥是 2 那么 a - c,D - F 等等......我已经制定了一个非常可靠的程序并且当我使用 check50 检查我的代码它出现了很多错误但输出是相同的...我只是不明白我的代码有什么问题..

#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

int main(int argc, string argv[])
{
    if (argc != 2)
    {
        printf("Usage: ./caesar key\n");
        return 1;
    }

    for (int i = 0; argv[1][i] != '[=10=]'; i++)
    {
        if (isalpha(argv[1][i]))
        {
            printf("Usage: ./caesar key\n");
             return 1;
        }
    }

    int key = atoi(argv[1]);

    string ptext;

    ptext = get_string("plaintext: ");

    printf("ciphertext: ");

    int n = strlen(ptext);

    for (int i = 0; i <= n; i++)
    {
        if (isupper(ptext[i]))
        {
            printf("%c", (((ptext[i] + key) - 65) % 26) + 65);
        }
        else if (islower(ptext[i]))
        {
            printf("%c", (((ptext[i] + key) - 97) % 26) + 97);
        }
        else
        {
            printf("%c", ptext[i]);
        }

    }
    printf("\n");

    return 0;
}

link 检查50 https://submit.cs50.io/check50/f7714d6b10c0b2e9fd1c1f01f4209195d8dc5163

您正在输出空终止符。

    int n = strlen(ptext);

    for (int i = 0; i <= n; i++)

您应该只循环到 i < n