0

So I tried doing my own Brainf*ck interpreter in C++, and everything was going fine until I tried this program:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[.-]

It just goes to the letter C and loops printing each character until going to 0.

I looked at other programs to see if they had the same thing; a Python module that interprets BF and a GitHub project also in C++ and each time the two other programs as well as mine outputted that:

♀♂A@?>=<;:9876543210/.-,+*)('&%$#"! ▼▲↔∟←→↓↑↨▬§¶‼↕◄►☼♫ ♠♣♦♥☻☺

It doesn't print the C and B but instead these symbols: "♀♂". How could I fix that?

1
  • That's fairly mystifying. Please post links to these three interpreters? Commented Jan 24, 2022 at 16:25

1 Answer 1

1

Your program will print several control characters, including the sequence "Carriage return, form feed, vertical tab, new line". The carriage return will move the cursor back to the beginning of the line where it will then start writing over the characters that are already there, namely the 'C' and 'B'. The symbols you're seeing are apparently how your terminal displays the form feed and vertical tab characters.

The new line character will then move the cursor to the next line, which is why only two characters are overwritten.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry for this comment being 3 days late but it definitely has to do with the way my interpreter(and the two other programs) display things then?
@JD470 It only has to do with the characters being printed and how your terminal displays them. The interpreter doesn't matter. You'll get the same behaviour if you write the same program in any other language using any other compiler/interpreter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.