0

I have, I think, finished caesar.c. However passing it through check50, returns the following.

Yet from what I can see in my code, and when i run my program vs the one in /home/cs50/pset2/caesar.c, they both produce the same output.

~/workspace/pset2/ $ check50 2016.caesar caesar.c
:) caesar.c exists
:) caesar.c compiles
:( encrypts "a" as "b" using 1 as key
\ expected output, but not "ciphertext: b\u0000\n"
:( encrypts "barfoo" as "yxocll" using 23 as key
\ expected output, but not "ciphertext: yxocll\u0000\n"
:( encrypts "BARFOO" as "EDUIRR" using 3 as key
\ expected output, but not "ciphertext: EDUIRR\u0000\n"
:( encrypts "BaRFoo" as "FeVJss" using 4 as key
\ expected output, but not "ciphertext: FeVJss\u0000\n"
:( encrypts "barfoo" as "onesbb" using 65 as key
\ expected output, but not "ciphertext: onesbb\u0000\n"
:( encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key
\ expected output, but not "ciphertext: iadxp, emk tqxxa!\u0000\n"
:) handles lack of argv[1]
https://sandbox.cs50.net/checks/d14b7073f33b452b84a0c8eaea12d81c

code removed per academic honesty policy

1
  • Is there anyway you could provide your code? Thanks Commented Jun 6, 2017 at 20:17

1 Answer 1

1

Your problem occurs here:

for(int i = 0, n = strlen(plaintext); i <= n; i++)

If we look at the first test case, plaintext is a, which has length of 1. Based on your for loop, you will allow keep incrementing i while it is less than or equal to 1. However, we have to recall how a string is stored in memory. In the case of a being stored as plaintext, we have:

----------
| a | \0 |
----------
  0    1

Index 1, i.e. the index that equals strlen(plaintext), will always be the NULL terminator. As a result, you are attempting to print NULL, which is why you aren't seeing a mistake on your end but why check50 is showing you \u0000. You will want to stop looping while i < n so as to stop before reaching a string's NULL terminator.

1
  • That was all it need. Your assistance has been greatly appreciated.
    – zemation
    Commented Jun 7, 2017 at 14:08

You must log in to answer this question.

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