0

I'm really struggling with this pset. I know my code isn't 100% right yet but I compiled it to test it out and it eventually compiled without errors. But the problem I'm having is that it's testing the input at the command prompt fine but then after that the program just ends - it doesn't go to GetString - it just stops.

I put the printf("test") function in to see what was happening and it doesn't print that either so it's like it's missing the whole code block out.

int main(int argc, string argv[])
{
//checks for correct input of one argument
if (argc !=2)
{
    printf("Please enter one word only after the ./vigenere command\n");
    return 1;
}
//checks for alphabetical text
    for (int i = 0; i < strlen(argv[1]); i++)
    {
        if (!isalpha(argv[1][i]))
        printf("Please enter alphabetical characters only after the ./vigenere command\n");
        return 1;
    }    

printf("test");
string text = GetString();
string key = argv[1];
int j = 0;
for (int i = 0; i < strlen(text); i++)
{
    if (isalpha(text[i]))
    {
        //for uppercase ascii values
        if (isupper(text[i]))

(rest of the code)

else
    {
        //if not an alpha returns the character unaltered
        printf("%c", text[i]);
        j++;
    }
}
printf("\n");
return 0;
}

What am I missing?

1

I see a problem here. After you type condition and it is more than one line you need those brackets:

    if (!isalpha(argv[1][i]))
    {
      printf("Please enter ...\n");
      return 1;
    }

Otherwise the program will execute return 1 in any case, not caring about the condition.

Hope this helps! If yes, please tick the check mark to accept it as answer, to keep tidy. If no, comments are welcomed!

0

I just recently programmed vigenere.c myself, so I am not a pro, but if you want your code to pass check50 it´s actually not supposed to prompt the user for a input via printf... Just the GetString function is enough. found that confusing at the beginning... and I also think your string key needs to go above you check for alphabetical text... I am not sure if this is solving your problem but might be good to know anyway...Good luck!

You must log in to answer this question.

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