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

Use the file hardware.txt Your program must do the following: Open the file hard

ID: 3570415 • Letter: U

Question

Use the file hardware.txt

Your program must do the following:

Open the file hardware.txt for reading and use it to create a binary file hardware.bin. Make sure to work with the proper structure type that will contain the following members: item code (integer), item name (string), quantity available (integer), item price (double).

Display information from a binary file in the readable format.

Close both files

Hardware file:

3 ElectricSander 7 57.98
17 Hammer 76 11.99
24 JigSaw 21 11.00
39 LawnMower 3 79.50
56 PowerSaw 18 99.99
68 Screwdriver 106 6.99
77 SledgeHammer 11 21.50
83 Wrench 34 7.50

Explanation / Answer

/*
* representing information for each tool using
* structures
*/
typedef struct {
int id; /* record number */
char name[128];
int quantity;
double cost;
} tool;/*
* read records from a file
* return number of actually records
* read from the file
*/
int ReadRecords(char *filename, tool rec[])
{
File *fp;
int nr=0; /* number of records */
/* open file for reading */
fp = fopen(...);
if (fp == NULL) { . . . . }
while (!feof(fp)) {
/* read a record into rec[nr] */
nr++;
}
fclose(fp);
}
return nr;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote