title: How do I use fprintf to print a struct member values that's defined in a header file?
body: <p>I'm currently taking a course on "structured programming methods". The course is not language based, but we generally use either C or C++.  Sometimes I'm required to write in one of these languages, sometimes I have to initially write in C and covert the code to C++, and sometimes I am allowed to write in what I prefer.  Quite possibly odd, I prefer to utilize C's (f/p)rintf. So, here's my issue:</p>
  
  <p>This is my header file for the <code>struct</code>:</p>
  
  <pre><code> #include &lt;string&gt;
   using namespace std;
  
   typedef string FNAME;
   typedef string LNAME;
   typedef string FULLNAME;
   typedef struct EmpRecord
   {
      FNAME firstname;
      LNAME lastname;
      FULLNAME fullname;
      float  hours, rate, deferred, gross, netpay,
             fedtax,  statetax,  ssitax;
    } EmpRecord;
  </code></pre>
  
  <p>Here's the "main".cpp:</p>
  
  <pre><code>        #define STRADD ", "
          #include &lt;stdio.h&gt;
          #include &lt;iostream&gt;
          #include &lt;fstream&gt;
          #include &lt;iomanip&gt;
          #include &lt;string&gt;
          #include "Struct.h"
          #include "Rates.h"
          #include "calcTaxesPlus.cpp"
          using namespace std;
  
          /*......*/
          void printEmpData(FILE *fp, struct EmpRecord *, float reghrs, float othrs);//3.8
          /*......*/
          int main()
          {
              float totRegHrs, totOtHrs, totRates, totGross, totDeferd,
                    totFed, totState, totSSI, totNet;
              float reghrs, othrs;
              float avgRate, avgRegHrs, avgGross, avgFed, avgSSI, avgNet,
                    avgOtHrs, avgState, avgDeferd;
              int   numEmp;
  
              EmpRecord emp;
              EmpRecord *Eptr;
              Eptr = &amp;emp;
  
              FILE * fp;
              fp = fopen("3AReport.txt", "w");
              if (fopen == NULL)
              {
                  printf("Couldn't open output file...!");
                  fflush(stdin);
                  getchar();
                  exit(-1000);
              }
              /*....*/
              printEmpData(fp, Eptr, reghrs, othrs);//3.8
              return 0;
          }
          /*....*/
          void printEmpData(FILE *fp, struct EmpRecord *e, float reghrs, float othrs) 
          {
              fprintf(fp, "\n%-17.16s   %5.2f       %5.2f     %7.2f     %6.2f     %6.2f %7.2f", e-&gt;fullname, e-&gt;rate, reghrs, e-&gt;gross, e-&gt;fedtax, e-&gt;ssitax, e-&gt;netpay);
              fprintf(fp, "\n                                %5.2f                 %6.2f     %6.2f       \n", othrs, e-&gt;statetax, e-&gt;deferred);
          return;
      }
  </code></pre>
  
  <p>I have tried a ton of combinations suggested by other questions/answers, but none seem to be dealing with a cross-language situation.  </p>
  
  <p>I'm basically looking for a solution that permits me to continue to use fprintf while leaving the bulk of the code C++.  </p>
  
  <p>I'm not looking for someone to code the solution for me, rather to explain what the issues are with this and how to logically go about circumventing them.</p>
  
  <p>Also, typedef is a requirement.
  Thanks-</p>