title: Embed yyparse(), generated by Flex and Bison, on CLI program written in C language
body: <p>I'm working on a improved version of mfcalc example given in the bison manual and you can find the code <a href="https://github.com/jcatumba/mfcalc" rel="nofollow">here</a>.</p>
  
  <p>I'm stuck trying to use yyparse() from main.c file, actually the code works fine with</p>
  
  <pre><code>int main (int argc, char const *argv[]) {
      init_table ();
      return yyparse ();
  }
  </code></pre>
  
  <p>but I want to add a prompt to that, so I wrote</p>
  
  <pre><code>int main (int argc, char const *argv[]) {
      char command[101];
      FILE *fp;
      init_table ();
  
      while (1) {
          printf ("[mfcalc]: "); /*prompt*/
          memset (command, 0x00, sizeof(command));
          fgets (command, 100, stdin);
          fp = fopen("command.txt", "w+");
          fprintf(fp, "%s", command);
          yyin = fp;
          yyparse ();
          fscanf (yyout, "%s", output);
          printf ("%s\n", output);
          fclose (fp);
      }
  }
  </code></pre>
  
  <p>this is, redefine yyin from <code>stdin</code> to a regular file, put a prompt message, execute the parser on yyin, read the output from yyout and print to screen. But this doesn't work correctly, I get just a blank line. When I prove the program I get:</p>
  
  <pre><code>[mfcalc]: 3 + 4
  
  [mfcalc]:
  </code></pre>
  
  <p>Also, the error codes are not shown. Any ideas to solve this?</p>
  
  <p>Thanks in advance.</p>