Ошибка тайм-аута CS50: когда я выполняю check50, все идет хорошо, кроме ошибки тайм-аута - PullRequest
0 голосов
/ 04 мая 2020

Я много раз пытался изменить выражения if ... но это не сработало. Я думаю, что мне нужно изменить оператор [arg c! = 1]. Я думаю, что в этом проблема ... Вот мой код. Я новичок здесь, поэтому go легко для меня. Спасибо!

#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(int argc, string argv[]) // Creating argc and argv to implement command-line arguments.
{
    int i = 0;
    string s = "0";
    if (argc != 2) // Ensuring that valid key is entered.
    {
        printf("User: ./caesar key\n"); // Printing error if key is not satisfactory.
        return 1;
    }
    int k = atoi(argv[1]); // Detecting key and assigning it to a varriable "k".
    if (k > 0) // Program condition: if key is satisfactoy, then cipher the message.
    {
        s = get_string("plaintext: ");
        for (i = 0; i < strlen(s); i++) // Program Loop.
        {
            if islower(s[i])
            {
                s[i] = ((((s[i] + k) - 97) % 26) + 97); // Preserving uppercase letters as uppercase while encrypting them. 
            }
            else if isupper(s[i])
            {
                s[i] = ((((s[i] + k) - 65) % 26) + 65); // Preserving lowercase letters as  uppercase while encrypting them.
            }
            else
            {
                continue; // Preserving miscellaneous characters.
            }
        }

    }
    else // Ensuring that valid key is entered.
    {
        printf("User: ./caesar key\n"); // Printing error if key is not satisfactory.
        return 1;  
    }
    printf("ciphertext: %s", s);
    printf("\n");
    return 0;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...