title: C Language - Printing array into text file
body: <p>I am trying to make a program in the C language that can take in employee information in array struct (not parallel) form and output it into a text file.
  The program will compare the job code and calculate the commission rate of the employee.
  I have 2 questions:</p>
  
  <p>1 - the commission of the salesPerson is always 0 even when I enter one of TEL, SAL, SSR. Is it a problem with my string comparison?</p>
  
  <p>2 - how do I output my results into a text file (inside the project folder)?</p>
  
  <p>Edit - I have figured out how to print my file into a txt. Thank you all for your help!</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  //job codes
  char TEL[4] = "TEL";
  char SAL[4] = "SAL";
  char SSR[4] = "SSR";
  
  //create a sales person structure
  struct salesPerson
  {
      char name[31];
      int salesID;
      char jobCode[4];
      double totalSales;
      double commission;
  }e[10]; //make an array of 10 employees
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      //get employee info
      for(int i=0; i&lt;3; i++)
      {
          printf("\nEnter the sales person's name: ");
          scanf(" %s", &amp;e[i].name);
          printf("\nEnter the sales person's ID: \n");
          scanf(" %d%*c", &amp;e[i].salesID);
          printf("\nEnter the sales person's job code: \n");
          scanf(" %s", &amp;e[i].jobCode);
          printf("\nEnter the total sales of the sales person: ");
          scanf(" %lf", &amp;e[i].totalSales);
  
          //determine commission based on jobCode
          if(strcmp(e[i].jobCode, TEL) == 0)
          {
              e[i].commission = e[i].totalSales*0.02;
          }
          if(strcmp(e[i].jobCode, SAL) == 0)
          {
              e[i].commission = e[i].totalSales*0.05;
          }
          if(strcmp(e[i].jobCode, SSR) == 0)
          {
              e[i].commission = e[i].totalSales*0.07;
          }
          else
          {
              printf("\n----------");
          }
      }
  
      printf("\n%d\n", e[0].commission);
      printf("\n%d\n", e[1].commission);
      printf("\n%d\n", e[2].commission);
  
      //print stuff to txt file
      FILE *fpOut, *fpIn;
      /*
      if ((fpIn = fopen("c:\\temp\\salesEmployees.txt", "w")) == NULL)
      {
          printf("Error opening the file for processing\n\n");
      }
      else
      {
          fpOut = fopen("c:\\temp\\salesEmployees.txt", "w");
          for(int i=0; i&lt;3; i++)
          {
              //fscanf(fpIn,"%[^\n]", &amp;e[i].name);
              //fscanf(fpIn,"%f%*c", &amp;e[i].salesID);
  
              fprintf(fpOut, "\nName: %s", e[i].name);
              fprintf(fpOut, "\nSalesID: %d*c ", e[i].salesID);
              fprintf(fpOut, "\nJob code: %s ", e[i].jobCode);
              fprintf(fpOut, "\nTotal sales: %.2lf", e[i].totalSales);
              fprintf(fpOut, "\nCommission earned: %.2lf", e[i].commission);
              fprintf(fpOut, "\n\n");
          }
  
          //fclose(fpOut);
      }*/
  
  }
  </code></pre>