characterbrainfuck

Why does every brainf*ck interpreter (except the web ones) show these characters? (♀♂)


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?


Solution

  • 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.