title: I am trying to read data from a file which is tab delimited but it is giving me errors
body: <p>I am writing a program which takes data that the user inputs and writes it into a file. Then the data must be output from the file. My issue is that whenever I try to output the data I am given outputs like this &quot;40�z&quot;. The first line is a header which I also must output and I have tried outputting it with fgets and printf.</p>
  <p>Here is the code.</p>
  <p>EDIT: I still had my file open in write mode while trying to read from it. After fixing that I can print the values I need but only in the terminal. If I try to use it anywhere else i get a core dumped error</p>
  <pre><code>#include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  //struct declaration
  typedef struct employee_data {
      char lastName[20];
      char id[11];
      double grossPay;
      double taxes;
      double netPay;
  }employeeData;
  //function declarations
  
  void writeEmpFile(employeeData data[], FILE* outFile);
  void readEmptFile();
  
  int main(){
      //variable definitions
      employeeData data[5];
      FILE* outFile;
      
      //create file empstat.txt
      outFile = fopen(&quot;empstat.txt&quot;, &quot;w&quot;);
      fprintf(outFile, &quot;NAME\tIDNUM\tGROSS\tTAXES\tNET\n&quot;);
      writeEmpFile(data, outFile);
      printf(&quot;\n&quot;);
      readEmptFile();
      return(0);
  }
  
  
  //function definitions
  
  void writeEmpFile(employeeData data[], FILE* outFile){
      int i;
      for (i = 0; i &lt; 5; ++i){
              printf(&quot;Enter Last Name (no spaces): &quot;);
              scanf(&quot;%19s&quot;, data[i].lastName);
              if ((strcmp(data[i].lastName, &quot;EXIT&quot;)) == 0){
                  break;
              }
              printf(&quot;Enter ID Number: &quot;);
              scanf(&quot;%19s&quot;, data[i].id);
              printf(&quot;Enter Gross Pay: &quot;);
              scanf(&quot;%lf&quot;, &amp;data[i].grossPay);
              printf(&quot;Enter Taxes: &quot;);
              scanf(&quot;%lf&quot;, &amp;data[i].taxes);
              data[i].netPay = data[i].grossPay - data[i].taxes;
              
              
              fprintf(outFile, &quot;%s\t%s\t%lf\t%lf\t%lf\n&quot;, data[i].lastName, data[i].id, data[i].grossPay, data[i].taxes, data[i].netPay);
              fclose(outFile);
          }
  }
  
  void readEmptFile(){
      FILE* outFile;
      outFile = fopen(&quot;empstat.txt&quot;, &quot;r&quot;);
      //temp variables
      char header[100];
      char h1[6];
      char h2[6];
      char h3[6];
      char h4[6];
      char h5[6];
      double d1;
      double d2;
      double d3;
      
      fgets(header, 10000, outFile);
      printf(&quot;%s&quot;, header);
      
      fscanf(outFile, &quot;%s%s%lf%lf%lf&quot;, h1, h2, &amp;d1, &amp;d2, &amp;d3);
      printf(&quot;%s\t %s\t %lf\t %lf\t %lf\n&quot;, h1, h2, d1, d2, d3);
      
      //fscanf(outFile, &quot;%s\t%s\t%s\t%s\t%s&quot;, h1, h2, h3, h4, h5);
      //printf(&quot;%s %s %s %s %s\n&quot;, h1, h2, h3, h4, h5);
      
      
      
  }
  </code></pre>