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



int main(int argc, string argv[])

{

    int i, n;
    if(argc !=2)
    {
        return 1;
    }
    /*key*/

    int k = atoi (argv[1]);

    /*Get String*/

    string p = get_string();

    /*loop*/

    for (i = 0, n = strlen(p); i < n; i++)
    {
        if(isalpha(p[i]))
        {
            if(isupper(p[i]))
            {
               p[i] = (p[i] -'A') + k % 26;
               p[i] = p[i] + 'A';
            }
            else
            {
                 if(islower(p[i]))
            {
               p[i] = (p[i] -'a' + k) % 26;
               p[i] = p[i] + 'a';
            }
            }
        }
    }

      for (i = 0, n = strlen(p); i < n; i++)
    {
        printf("%c", p[i]);
    }
    printf("\n");
}

Please assist when I am running the code it is taking as correct output and when I am doing check50 it is not accepting any output. Can you please help?

Regards, Arivezhil

0

check50 is running correctly. I ran your code and got the following output:

~/workspace/test/pset2/ $ check50 cs50/2017/x/caesar
Connecting.....
Authenticating.....
Preparing........
Uploading.........
Running checks.........
:) caesar.c exists.
:) caesar.c compiles.
:( encrypts "a" as "b" using 1 as key
    expected prompt for input, found none
:( encrypts "barfoo" as "yxocll" using 23 as key
    expected prompt for input, found none
:( encrypts "BARFOO" as "EDUIRR" using 3 as key
    expected prompt for input, found none
:( encrypts "BaRFoo" as "FeVJss" using 4 as key
    expected prompt for input, found none
:( encrypts "barfoo" as "onesbb" using 65 as key
    expected prompt for input, found none
:) handles lack of argv[1]
See https://cs50.me/checks/6790c412456040dc5ee0e7d094a233762a6a8055 for more detail.

Both check50 and my execution of the code tells me that there's a problem with the code. Specifically, the code has no prompt for input to the user that asks for the text to encode. Perhaps it would help to review the exact requirements of the pset?

If you are having trouble running check50, it would help to edit your question and post a screenshot of the command used to execute check50 and the result.

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

4
  • I modified code still its not working as expected. Can you please assist further? Sep 26 '17 at 5:25
  • My crystal ball is still in the shop. Can't say anything without seeing the current code.
    – Cliff B
    Sep 26 '17 at 5:41
  • Thank you Cliff.. Can you please respond on below? Sep 26 '17 at 11:56
  • Thank you Cliff it is working now. I have included and changed the printf command Sep 26 '17 at 12:03

You must log in to answer this question.

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