title: Brainfuck interpreter problems
body: <p>I'm new to C. Currently I'm trying to write a Brainfuck interpreter. I have tried this so far.</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  
  char    *line;
  int     curr_pos;
  
  void    interprete(char *coms)
  {
      int a;
      int curr_loop;
  
      a = -1;
      curr_loop = 0;
      while (line[++a])
          line[a] = 0;
      a = -1;
      while (coms[++a])
      {
          if (coms[a] == '+')
              line[curr_pos]++;
          else if (coms[a] == '-')
              line[curr_pos]--;
          else if (coms[a] == '&gt;')
              curr_pos++;
          else if (coms[a] == '&lt;')
              curr_pos--;
          else if (coms[a] == '.')
              write(1, &amp;line[curr_pos], 1);
          else if (coms[a] == '[')
          {
              if (line[curr_pos])
                  curr_pos++;
              else
              {
                  curr_loop = 1;
                  while (curr_loop)
                  {
                      ++a;
                      if (coms[a] == '[')
                          curr_loop++;
                      else if (coms[a] == ']')
                          curr_loop--;
                  }
              }
          }
          else if (coms[a] == ']')
          {
              if (line[curr_pos])
              {
                  curr_loop = 1;
                  while (curr_loop)
                  {
                      --a;
                      if (coms[a] == '[')
                          curr_loop--;
                      else if (coms[a] == ']')
                          curr_loop++;
                  }
              }
              else
                  curr_pos++;
          }
      }
  }
  
  int main(int ac, char **av)
  {
      if (ac == 2)
      {
          curr_pos = 0;
          line = malloc(sizeof(char) * 4096);
          interprete(av[1]);
      }
      write(1, "\n", 1);
  }
  </code></pre>
  
  <p>It works only without loops ("[" and "]").When I try:</p>
  
  <pre><code>++++++++++[&gt;+++++++&gt;++++++++++&gt;+++&gt;+&lt;&lt;&lt;&lt;-]&gt;++.&gt;+.+++++++..+++.&gt;++.&lt;&lt;+++++++++++++++.&gt;.+++.------.--------.&gt;+.&gt;.
  </code></pre>
  
  <p>It gives me the output </p>
  
  <pre><code>^B^A^H^H^K^B^Q^K^N^H^@^C^@
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>Hello World!
  </code></pre>