I'm working on a brainfuck interpreter

So that program seems to run if I change the memory type to char. However, it prints out garbage. When I changed it to just print out the character codes (not the characters themselves) I got something more like the expected output except there was still garbage in it.

Like it prints out 49 (char code for 1) twice, then a comma, then a space.

49 49 44 32 49 49 44 32 50 40 44 32 51 31 44 32 53 13 44 32 56 -14 44 32 61 -59 44 32 69 125 44 32 82 8 44 32 103 75 44 32 -119 25 44 32
As characters (only partly translated):
11, 11, 2(, 3?,
? is a unit separator, shows up as a space in my terminal but isn't a space character proper.

Note: It's garbage whether I use unsigned char or char. The negative values only show up with the memory of type char and not unsigned char, but I get the same output. The issue with printing each character as a character seems to be the 13 which is a carriage return. Since it's not a newline, this causes the curser to go back to the start of the current line and overwrite whatever was there. So it's correctly calculating some things, but then gets off somewhere. I tried the Fibonacci program in another interpreter and it worked correctly, so the issue is somewhere in your program. I haven't figured it out yet.

/r/learnprogramming Thread Parent