Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am coding in C and i can get the program to run but can not get the file to op

ID: 3762311 • Letter: I

Question

I am coding in C and i can get the program to run but can not get the file to open in the program. I just need some help figuring out this problem! My code is below!

My text file is

205   14   7.54   N   45
3498   64   17.98   Y   38
1328   38   25.75   Y   49
9054   76   10.43   N   42
213   64   8.29   N   47
659   14   7.52   N   41
5487   14   25.75   Y   52
4326   38   7.54   N   36
1267   76   8.29   N   40

#include <stdio.h>
#include <stdlib.h>

// Function Declarations
int getData (FILE* pDataIn,
             int* empNo, int* dept, float* payRate, char* exempt, int* hours);
int writeData (FILE* pDataOut,
               int empNo, int dept, float payRate, char exempt, int hours, float basePay);
void calcBasePay (float payRate, int hours, float* basePay);

int main (void)
{

// Local Declarations
   FILE* pDataIn;
   FILE* pDataOut;

   int empNo;
   int dept;
   float payRate;
   char exempt;
   int hours;
   float basePay;

// Statements
   printf("This program creates a payroll register... ");
   if (!(pDataIn = fopen("emp_data.txt", "r")))
   {
    printf("Error opening employee file ");
    return 100;
   } // if open input

   if (!(pDataOut = fopen("emp_data.txt", "w")))
   {
    printf("Error opening employee file ");
    return 102;
   } // of open output

   while (getData
         (pDataIn, &empNo, &dept, &payRate, &exempt, &hours))
    {
     calcBasePay (payRate, hours, &basePay);
     writeData (pDataOut, empNo, dept, payRate, exempt, hours, basePay);
    } // while

    fclose(pDataIn);
    fclose(pDataOut);

    printf("End employee payroll register ");
    return 0;
} // main

/*==================getData==================
Reads employee data from text file.
    Pre   pDataIn is an open file.
          empNo, dept, payRate, exempt, hours, basePay pass by address
    Post reads employee information
          if data read    --returns 1
          if EOF or error --returns 0

*/
int getData (FILE* pDataIn, int* empNo, int* dept, float* payRate, char* exempt, int* hours)
{
// Local Declarations
   int ioResult;

// Statements
   ioResult = fscanf(pDataIn, "%d %d %f %c %d", empNo, dept, payRate, exempt, hours);

   if(ioResult == EOF)
   return 0;
   else
   return 1;
} // getData

/*==================calcBasePay==================
Determine Base Pay based on hours and payRate.
    Pre   payRate and hours contain the variables.
    Post basePay copied to address.
*/
void calcBasePay (float payRate, int hours, float* basePay)
{
// Statements
   *basePay = (payRate*hours);
   return;
} // calcBasePay

/*==================writeData==================
Writes employee information, which now includes basePay, to output file.
    Pre   spDataOut is an open file
          empNo, dept, payRate, exempt, hours, basePay have values to write.
    Post Data written to file.
*/
int writeData (FILE* pDataOut, int empNo, int dept, float payRate, char exempt, int hours, float basePay)
{
// Statements
   fprintf(pDataOut, "%d %d %f %c %d %f ", empNo, dept, payRate, exempt, hours, basePay);
   return 0;
} // writeData

Explanation / Answer

Try to bring the file in the same library