0

For some reason my check50 is failing but the code runs perfectly?

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

            void Encrypt(char c,int k);

            int main(int argc, string argv[])
            {
               //ensure argc is 2 or fail
               if(argc != 2)
               {
                   printf("unsupported number of commandline arguments\n");
                   printf("Please enter an integer!\n");
                   return 1;
               }
               //correct argument run code
               else
               {
                    //change key into intager
                    int k = atoi(argv[1]);


                    //get input
                    string input = get_string();
                    printf("Plaintext:  %s\n", input);
                    //Ensure string value
                    if(input != NULL)
                    {
                        int l = strlen(input);
                         printf("ciphertext: ");
                        //loop through input to get characters
                        for(int i = 0; i < l; i ++)
                        {

                            //encrypt
                            Encrypt(input[i], k);
                        }
                    }
               }
               printf("\n");
                return 0; 

            }
            //Encrypt function takes character to change and key from argv[1]
            void Encrypt(char c, int k)
            {
                printf("%c",c + k);
            }

Console Error

enter image description here

1 Answer 1

1

You need to read the specification carefully. The error code expected output, not a prompt for input is given because the check50 program is looking for exact output per the specification, which is this:

$ ./caesar 13
plaintext:  HELLO
ciphertext: URYYB

Your code currently asks for a string before printing out the plaintext user input again. In the above example, HELLO is typed in by the user. Your code would look like this:

$ ./caesar 13
HELLO
plaintext:  HELLO
ciphertext: URYYB

However, once this problem is solved, I think you'll find you have problems with your Encrypyt() function. You have coded no wrap-around in, so 'z' with a key of 3 should become 'c', yours will show a non-alphabetical special character.

1
  • Yes I see the issue thank you :)
    – Jason
    Commented Jan 25, 2017 at 11:38

You must log in to answer this question.

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