Terminal returning incorrect values


#1

Hello! I have more than once experienced this so if anyone has any advice on what i’m doing wrong, or if it is just a bug in the system, that would be great.

I wrote a code (cs50 pset2 initials) and on my terminal output instead of the 3 characters i was supposed to get, the output was producing 4 (or more) characters. I ran the cs50 “test” and it compiled and ran as it was supposed to (outputting 2 characters for a 2 name input, 3 for a 3 name input) so i know it’s not a problem with the code.
I updated the terminals and even opened a new terminal to run the code but was still returning too many characters (ccmh for my name instead of cmh, for instance.
This has happened before so i know it’s not just this terminal.
any help would be great!
Thank you!


#2

Hi,
this is extremely unlikely to be a problem with terminal, since it happens only for one program.
passing the test doesn’t mean that your program is correct, since that only tests for very a small set of inputs.

To verify this is not terminal issue, try running initials with the exact string check50 does (capitalized the same way)
and try running with some random strings like aaaaaaaaaa


#3

Hi harutyun,
thank you for the response.
On the screenshot included (in the original post) i only ran the last example from check50 (robert thomas bowden) , because in check50 it ran fine (returned RTB) but when i ran it myself it returned RRTB.
I also ran a lot of other words and strings and it worked fine on some of the words but not on others.
And there didn’t seem to be any logic behind why certain words worked and others didn’t.
I understand there could be an issue with my code, for sure, but what i don’t understand is why it would work fine in check50 but not when i ran it myself.

thanks for any help!


#4

The last example from check50 starts with capital R and you ran with small r.
For more fun try robeRt thomas
Also when output is confusing don’t forget to use the debugger.


#5

Ok great, thank you!