0

having some issue with check50 on the vigenere pset. I seem to have the program working correctly, but the check50 output does not correlate with what I am seeing in terminal.

I have researched the current questions about the trailing printf("\n"); on output and can confirm this isn't the issue (although the sandbox report seems to imply it in some of its tests). It seems the output when compiled and run by check50 is completely different to the one I am seeing. Evidence in screenshot:

Check50 Issue

Sandbox Report Link: https://sandbox.cs50.net/checks/c93f24e075f44649987c82d93ecda7d6

Any thoughts would be appreciated. Happy to post some code if it would help someone decipher what is happening here.

I realise I still would fail the last test, as I handle it rather foolishly, I'll add an isdigit check now.

Thanks in advance.

char buf[strlen(argv[1])];
for (int i = 0; i < strlen(buf); i++)
{
    buf[i] = argv[1][i];

[mod edit to remove all but necessary code]

  • Yeah if you can add the code. You are probably right. Your program does output the correct when run by you. – ChrisG Aug 14 '15 at 18:32
0

The problem lies here:

char buf[strlen(argv[1])];
for (int i = 0; i < strlen(buf); i++)

When you declare buf the compiler gives you memory for your array but it is not initialised. When you then call strlen(buf) on that memory, the return value of strlen is undefined, as strlen is looking for a null character to indicate the end of a string.

As a result, your buf array may be, say, 3 chars long, but strlen may report any size. In the case of your check50 results, on that run, it ended up as one char long, which is why check50 is saying your code produced CBSGPP for BARFOO with a key of BAZ ... buf was actually "B" rather than "BAZ".

Change that loop to use the known value (i.e., strlen(argv[1]) and you will pass all checks.

| improve this answer | |

You must log in to answer this question.

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