title: Prefix math expressions array to parse tree - recursion to move with array
body: <p>I want to create a math expression parse tree from an array that is sorted in prefix notation. (BTW, will it be easier with postfix?)</p>
  <p>For example:</p>
  <blockquote>
  <p>Infix: ((((3+4)*5)/2)+8)</p>
  <p>Prefix: + 8 / 2 * 5 + 4 3 (the function will be given this)</p>
  </blockquote>
  <p>Below is my code, in short, it's suppose to go through the prefix array linearly, with each recursive call to move forward in the array.</p>
  <p>If current is an operator make a recursive call to left and right, if a digit, just make it and return.</p>
  <pre><code>TreeNode * parsetree(char  *arr){
  
      if (*arr == '\0'){
          return NULL;
      }
      TreeNode *curr=NULL;
  
      if (isop(*arr)){
          curr = treenodemaker(*arr, NULL, NULL); 
          arr++;
          curr-&gt;left = parsetree(arr);
          arr++;
          curr-&gt;right = parsetree(arr);
      }
      else if (isdig(*arr)){
          curr = treenodemaker(*arr, NULL, NULL);
      }
      return curr;
  
  }
  </code></pre>
  <p>The problem is moving up the array doesn't work well in the recursion, for example, given:
  <code>*-39+21</code> which is <code>((1+2)*(9-3))</code></p>
  <p>It creates the left part correctly, but the right side is just <code>3</code> I understand that when it leaves the first call to the left, it's just in <code>arr+2</code> instead <code>arr+4</code>. So the question is, how can I make the address of the array move with the recursion? (preferably without using static or global variables)</p>