Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you use the comma command in Brainfuck?

I’ve been experimenting with the BF esolang today, as I graduated from hello world to an addition program, (which requires the data take in command), I could not for the life of me figure out how this command works. At first I thought you would use the period command for data out, and then the next time you call the comma, it takes in that data. After looking at some interpreters in java, it looked like it took data from the next byte, but this didn’t seem to work.

Basically every source, including the main wiki page, has the same rudimentary explanation, stating that this command "takes in" a byte of data and stores it at the pointer. I’m not sure where this data comes from, every tutorial that I found also gives the same explanation.

I tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

++++++++++[>++++++<-]>+++++. generates A at pointer 1 <, goes to pointer 0 and *should* take in A

This still didn’t work. This is probably a dumb question, but this is my last resort for understanding this.

>Solution :

The period prints the value at the pointer to an output stream.

The comma accepts a byte from an input stream and stores that value at the memory being pointed at.

The output stream could be printing to the terminal, the input stream could be data entered at the terminal from a keyboard.

The period is equivalent to the C code: putchar(*ptr), whereas the comma is equivalent to: *ptr = getchar().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading