Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Language Program using File Access: Ask user to input details of book (File Write) and display records (File Read) 1. Title 2. Author 3.

C Language

Program using File Access: Ask user to input details of book (File Write) and display records (File Read) 1. Title 2. Author 3. Genre 4. Total Pages 5. Publisher

**Please do add comments on how the program works. Thank you!!

Please strictly follow the following:

- Modular Code (Use functions)

- Records goes to info.dat and it grows size every time a record is added

- count.dat should hold the number of records

- Show number of records in view records

- Ask to user to add new record [Y/N] if no, the program closes (ignore case for the letter)

- View all records

- Edit selected record

- Add new record (Title, Author, Genre, Total Pages, Publisher)

- Delete selected record and can even delete all records

Structure of code should be like this

**This needs improvements please do add the features above

image text in transcribed

ON 11 1 #include 2 #include 3 4 void readke() { 5 FILE "pi 6 char nanel2e), gender 7 int age, count) BB if ((fp-fopen("count.dat", "rb"))--NULL) //ecunt, dat holds the number of records, try to open the file fp = fopen("count.dat","w+b"); // if file does not exist, create it le count. 11 for the first record fwrite(&count, sizeof(int),1,fp); 1 write count on the file count.cat 12 fclose(fp) W cost count det 13 14 else { 15 fread(Rcount,sizeof(Int),1,fp); Il countdot already exists 16 counts #update the number of records 17 reind (fp) 18 fueritedcount, sizeof(int),1,fp); write count on the file count.dot 19 fclose(fp) 1 close court.dat 20 21 fp - fopen("info.dat", "ab"); 11 open database for apprend, sf not yet created the creste datose printf(" Please enter name of student: >> scanf("%s"name); 24 Eetchar(); 25 printf("Please enter gender of student (H/F): "); 26 scanf("%c,&gender) 27 printf("Please enter age of student: "> 28 scanf("%d", dage); 29 strcat(nane, " ); // maline is necessary to indicate end of string 30 fputs(nare, fp); write one to database 31 tputc(gender, fp); write gender to database 32 furite (Sage,sizeof(int),1,fp); 1/ write og to database fclose(fp): // close database 34 36 void output) 37 FILE "p) char name[20], gender 39 int n, age, county 40 If ((fp-fopen("count.dat", "rb")) --SULL) { 11 count dat holds the number of records, try to open the printf("Nanber of records: 0. "); // file does not exist, ne records yet ) else { fread(acount, sizeof(int),1,fp) // count dot cists direddy 45 fclose(fp); I read the record courts, then close fille 46 printf("Nanber of records: 3d. 1n.count); Il display the number of records fp-fopen("info.dat", "rb"), 1 open the database 48 L for (ne) nccount; no) // display at the records 49 fgets(nane, 19, fp); Il extract the name 50 printf(" Name : %s".name) 51 gender . fgete(fp); // extract the gender 52 printf("Gender: sc.gender) 53 fread(Rage, sizeof(int), 1,fp) 11 extract the age 54 printf(" age = $d ", age); 55 56 fclose(fp) // close the database 57 58 59 60 void main() 61 char ans='Y' 62 output(); // output the records on the screen 630 do 64 readi) Waste for record from user 65 printf(" tant to add another record? (V/N): *); // olla multiple records 66 while(getche() --'Y') 67 68 41 42 44

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions