Creating a program to read a text file


Discuss the below:

Creating a program to read a text file and create a payroll register. The register will contain this data:

Employee(print left-justified)

Department

Pay Rate

Exempt

Hours worked

Base pay(pay rate * hours worked)

Overtime pay (for nonexempt employees. An employee is exempt if Y appears in the exempt column. Overtime is paid at time and one half for all hours worked over 40)

Total pay.

Employee No.	Department	Pay Rate	Exempt	Hours Worked
============	==========	========	======	============
0101		41		8.11		y	49		
0722		32		7.22		N	40
1273		23		5.43		y	39
2584		14		6.74		N	45
#include 
#include

#define BUFSIZE 100

int main(void)
{

FILE *fp;

char buf [BUFSIZE];
int c;
int closeStatus;
FILE *fpIn;
FILE *fpOut;

printf("Begin file copy\n");

if ((fpIn=fopen ("input.txt", "r")))
{
printf("Error in opening input.txt for reading");
return (1);
}
if ((fpOut=fopen ("input.txt", "w")))
{
printf("Error opening input.txt for writing");
return (2);
}
while((c = fgetc(fpIn)))
fputc(c, fpOut);

fclose(fpIn);
closeStatus = fclose(fpOut);
if (closeStatus==EOF)
{
printf("File close error.\a\n");
return 201;
}

printf("File successfully created\n");
return 0;
}

Solution Preview :

Prepared by a verified Expert
Database Management System: Creating a program to read a text file
Reference No:- TGS01932497

Now Priced at $20 (50% Discount)

Recommended (95%)

Rated (4.7/5)