I knocked off a couple or so struct members, and changed the print out a bit, but you get the idea. Contents of the payroll.txt file, is at the bottom of the program.
Code:
#include <stdio.h>
#include <string.h>
struct employee1 {
int num;
char first_name[8];
char last_name[8];
int id_number;
int year;
double pay_rate;
double sthours;
double ot_hour;
double double_hour;
double gross_pay;
};
int main() {
int i, n ;
struct employee1 emp;
char junk[200];
FILE *writeptr = fopen("payroll.txt", "rt");
fgets(junk,200, writeptr);
//printf("Enter record number to be edited\n");
//scanf("%d", &employee.num);
//moving file pointer to position of record user requested
// fseek(writeptr, (employee.num-1) * sizeof(struct employee_data), SEEK_CUR);
fscanf(writeptr, "%d %s %s %d %lf %d %lf %lf %lf %lf" , &emp.num,
emp.first_name, emp.last_name, &emp.id_number, &emp.pay_rate, &emp.year,
&emp.sthours, &emp.ot_hour, &emp.double_hour, &emp.gross_pay);
printf("\n Number: %6d First Name: %-15s Last Name: %-15s \
\n ID No: %-8d Pay Rate: %-10.2lf Year: %-10d \
\n ST Hours: %-.2lf 1.5 Hours: %-.2lf 2x hours: %-.2lf Gross Pay: %-.2lf ",
emp.num, emp.first_name, emp.last_name, emp.id_number, emp.pay_rate,
emp.year, emp.sthours, emp.ot_hour, emp.double_hour, emp.gross_pay);
printf("\n\n\t\t\t press enter when ready");
fclose(writeptr);
getchar();
return 0;
}
/*
Contents of the payroll.txt file:
number First name Last name id no. pay rate year sthours 1.5 hours 2x hours
Gross pay
1 p w 1 1.00 1 1.00 1.00 1.00
4.50
*/