/* Course Number : ISYS 116 Student Name : Jason Gradziel Student Number : 826-135-535 Professors Name : Gene Rychlewski Class Name : Thursday Lab Title : */ #include #include #include FILE *Safe_fopen(char *, char *); void Safe_fclose(FILE *); typedef struct { char id_no[3]; int q_o_h; double price; } PART_REC; main() { clrscr(); FILE *input_file, *output_file; PART_REC employee; char input_file_name[51], output_file_name[51]; int record_count = 0; //printf("\nEnter the name of the text file: "); //printf("\nEnter the name of the input file: "); //gets(input_file_name); //printf("\nEnter the name of the output file: "); //gets(output_file_name); //input_file = Safe_fopen(input_file_name, "r"); output_file = Safe_fopen("a:output.dat", "w"); printf("\nThe file was succfully opened."); fprintf(output_file, "\n\n%15s%15s%15s\n", "EMPLOYEE NUMBER", "DAYS WORKED", "HOURLY RATE"); input_file = Safe_fopen("a:input.dat", "rb"); fread(&employee, sizeof (PART_REC), 1, input_file); //printf("\nEnter the name of the sequential file: "); //gets(output_file_name); //output_file = Safe_fopen(output_file_name, "wb"); while ( !feof (input_file)) { ++record_count; fprintf(output_file, "\n\n%15s%15d%15.2f", employee.id_no, employee.q_o_h, employee.price); fread(&employee, sizeof(PART_REC), 1, input_file); } //while ( fscanf(input_file, "%s %d %lf", employee.id_no, &employee.q_o_h, &employee.price) == 3) //{ // fwrite(&employee, sizeof(PART_REC), 1, output_file); // ++record_count; //} printf("\n\n%d records were read.", record_count); Safe_fclose(input_file); //printf("\nThe file was closed succfully."); Safe_fclose(output_file); printf("\nThe file was closed succfully."); getch(); return 0; } FILE * Safe_fopen(char *f_name, char *mode) { FILE *file_ptr; if ( (file_ptr = fopen(f_name, mode)) == NULL) { fprintf(stderr, "\nError: File %s cannot be opened.", f_name); getch(); exit(1); } return file_ptr; } void Safe_fclose(FILE *file_ptr) { if ( fclose(file_ptr) == EOF) { fprintf(stderr, "\nError: The file cannot be closed."); getch(); exit(1); } return; }