0

I can't understand what is the problem in code, it says "timed out while waiting for program to exit. I will be thankfull for any advices!

I can't understand what is the problem in code, it says  "timed out while waiting for program to exit"

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

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

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

    int k = atoi(argv[1]);

    string plaintext = get_string("Plaintext: ");
    printf("ciphertext: ");

    for (int j = 0; j < strlen(plaintext); j++)
    {
        if (isupper(plaintext[j]))
        {
            printf("%c", (plaintext[j] - 65 + k) % 26 + 65);
        }
        else if (islower(plaintext[j]))
        {
            printf("%c", (plaintext[j] - 97 + k) % 26 + 97);
        }
        else
        {
            printf("%c", plaintext[j]);
        }
     }
    printf("\n");
}

}

1 Answer 1

1

It seems that there's a problem with the for loop constructions.

Check your curly brace pairings.

The first for loop doesn't close until line 44. It should close on line 22, before the "int k..." line.

The result is that the entire program executes, and then tries to execute a second time on the next pass. So, the program prompts for plaintext input a second time, but check50 is just waiting for it to end.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Thank you very much! It really works now!
    – Soremegis
    Feb 14, 2023 at 9:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .