0

I am running check50 but it will not accept my output as correct. For example, one of the conditions needed to be satisfied is: enter image description here When I run the code below I obtain the desired output (CAQGON) but according to the image above I do not have an output as noted by the blank space below "Actual Output". I suspect it is because I prompt the user to input the key word directly from the command line when I used "int main (int argc, string argv[])" because when I use get_string() instead, check50 is able to recognize the output. Any help would be appreciate, thanks.

#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int shift;
int j;
int main(int argc, string argv[]) //user inputs the string(s) and the last string in argv is designated as the key
{
    if (argc > 2) //I dont want to limit user input //isdigit() can only read char not strings
    {
        int key = strlen(argv[argc - 1]);
        for (int i = 1; i < argc - 1; i++)
        {
            for (j = 0; j < strlen(argv[i]); j++)
            {            
                if (isalpha(argv[i][j]) == 0 && isdigit(argv[i][j]) == true)
                {
                    printf("%c", argv[i][j]);  
                }          
                else if (isalpha(argv[i][(j)]) != 0)
                {
                    shift = toupper(argv[argc - 1][j % key]) % 26 - 13;
                    //shift is for the key and does ! discern betwen upper and lowercase by treating all key as uppercase letters
                }
                else
                {
                    shift = 0;
                }      
                printf("%c", argv[i][j] + shift);
            }
            printf(" "); //spacing in between words    
        }
        printf("\n");  
    }
    else
    {
        printf("./vigenere keyword\n");
        return 1;
    }
}

1

I suspect it is because I prompt the user to input the key word directly from the command

That's exactly why. The spec requires that your program gets the key from the command line, and once you've verified that it is a valid key, that you prompt the user for the plaintext.

You aren't doing that, so check50 will report an error.

1
  • Awesome thanks for reinforcing that thought, it's working great now :) – Gil Ong Jan 19 '20 at 6:08

You must log in to answer this question.

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