Question: Sample run 2 : Books: id: 1 name: Let _ Us _ C author: Y . Kanetkar quantity: 1 1 rackno: 3 id: 2 name:
Sample run :
Books:
id:
name: LetUsC
author: YKanetkar
quantity:
rackno:
id:
name: HeadFirstC
author: DGriffiths
quantity:
rackno:
id:
name: CProg
author: CBrown
quantity:
rackno:
Enter id of the book to be updated:
How many books will be added or removed:
Books:
id:
name: LetUsC
author: YKanetkar
quantity:
rackno:
id:
name: HeadFirstC
author: DGriffiths
quantity:
rackno:
id:
name: CProg
author: CBrown
quantity:
rackno:
Enter id of the book to be deleted:
Books:
id:
name: LetUsC
author: YKanetkar
quantity:
rackno:
id:
name: CProg
author: CBrown
quantity:
rackno: I have a C Programming assaignment. We have to complete a code structure. I will put the required sample run for the code. Also, there is a binary file library.bin which contains records of books in a library. Each book record will be stored using bookData struct. I will also put the library.bin file. Assaignment Description: You are given a binary file library.bin you can download from Moodle which contains records of books in a library. Each book record will be stored using bookData struct.
typedef struct
int id; book id
char name; book name
char author; author of book
int quantity; quantity of book
int rackno; rack no of the book
bookData;
Library.bin file consists of records. of them are blank records. The other records not blank are placed in specific positions of the binary file based on their ids. For example, if id of the book is its record is the fifth record in the file. The size of each record is equal to the size of bookData struct. The records are sorted according to their id number.
Implement the following functions:
void showRecords It shows and lists all records in the binary file.
int updateRecordint id int diff This function updates quantity of the book whose id is provided in the parameter id The update is performed by adding the number in the parameter diff to the quantity of the book with the given id If there is a book record with the given id the new quantity of the book is written to library.bin and the function returns ; otherwise, it returns
int deleteRecordint id This function removes the book with the given id from binary file librarybin by setting its fields to If the given id is found in the binary file, the book record will be removed from the binary file and the function returns ; otherwise, it returns A skeleton code HWskeleton.c provided in Moodle. Note that, in each function, you should open library.bin,
perform your task, and close the file. In showRecords fuction, open the file with rb in updateRecord and deleteRecord function open the file with rb
Hint: fseek is used to move file pointer associated with a given file to a specific position. You need to use fseek function to add, update and delete any record in binary file. Here is the code structure that needs to be complete: #include
#include
typedef struct
int id; book id
char name; book name
char author; author of book
int quantity; quantity of book
int rackno; rack no of the book
bookData;
void showRecords;
int updateRecordint id int diff;
int deleteRecordint id;
int main
int id;
int diff;
printfBooks:;
showRecords;
printfEnter id of the book to be updated:";
scanfd&id;
printfHow many books will be added or removed:;
scanfd&diff;
if updateRecordid diff
printfThere is no book with id did;
printfBooks:;
showRecords;
printfEnter id of the book to be deleted:";
scanfd&id;
if deleteRecordid
printfThere is no book with id did;
printfBooks:;
showRecords;
return ;
void showRecords
implement here
int updateRecordint id int diff
implement here
int deleteRecordint id
implement here
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
