0

My code compiles but check 50 tests print errors like this:

:( encrypts "barfoo" as "yxocll" using 23 as key \ expected output, but not "barfoo\nciphertext:yxocll"

I've tried every modification I can think of. The encryption seems correct but the print statements are running all together. I've tried adding parenthesis but no success.

  if (argc<2) //key is entered on command line 
    {
    printf("Please enter your key."); //prompts if no key is entered
    return 1;
    }

else if (argc>=2) 
    {

    printf("plaintext:");
    char* word = GetString(); 
    printf("%s\n", word);      
    printf("ciphertext: ");       

    int num = atoi(argv[1]); 

    for(int i=0; i<strlen(word); i++) 
-1

You shouldn't be printing the plaintext word. Recall that the spec shows:

$ ./caesar 13
plaintext: HELLO  (where HELLO is what the user typed)
ciphertext: URYYB

Your program is doing this when you run it, right?:

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

So there are 2 problems there. The first is that extra printing. Can you see what the second issue is? Pay attention to spaces.

4
  • 3) It doesn't print out the result you showed. My concern is that it passes check50 which it doesn't because too much is printing on one line. See the top error message to see what it prints out. It's at the top of my post. How do you think the word plaintext appears on the terminal if it isn't printed? – Android1 Mar 12 '17 at 11:21
  • 1)The lower part of the code contains most of the print statement of the ciphertext. 2) The requirement of the exercise is that you print "plaintext:" Then call for the string input from the user. On the following line you print out 'ciphertext:' then the ciphertext is printed out next to that. As you can see from the error message it's printing the string input, the word ciphertext and the ciphertext in one line. As you can see, the ciphertext printout is contained in the algo, which you deleted. – Android1 Mar 12 '17 at 11:22
  • I removed the print statements as you suggested. Now the check50 result is 'expected output not a prompt for input'. – Android1 Mar 12 '17 at 11:47
  • I've solved the problem and the code has passed check50. I moved the for-loop forward and moved the printf lines. I also removed the print line for the plaintext input as you suggested so it wouldn't be entered twice and removed a space. For the info of others, we ARE required to print the lines 'plaintext' and 'ciphertext' in order to pass check 50. Thanks for your advice. – Android1 Mar 12 '17 at 14:19
0

It is supposed to be a backslash n(\n) You just put an forward slash one (/n) - which is wrong and gives a error in check50

1
  • I think you might be looking at one of the comments. There's only one new line and it's \n. The comments start with // . Thanks anyway. ;) – Android1 Mar 16 '17 at 14:57

You must log in to answer this question.

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