[Solved] Why the brainfuck interpreter in C may not work when executing a program with loops?


‘]’ should jump back if cell is nonzero

Hugely convoluted approach; you want to put the matches in the brackets array so it’s like

case '[':
  if (arr[ptr] == 0)
    i = brackets[i];
  break;

Why i = brackets[j][1] – 1; and not just i = brackets[j][1]; (extra speed cost)

Having j and pos laboriously correlate is a red flag

Forgot to free all those little 2-int arrays

2

solved Why the brainfuck interpreter in C may not work when executing a program with loops?