Question: 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 record
Structure of code should be like this (this is only a sample code)
**This needs improvements please do add the features above
#include
void readKB(){ FILE *fp; char name[20], gender; int age, count;
if((fp=fopen("count.dat","r+b"))==NULL){ fp = fopen("count.dat","w+b"); count = 1; fwrite(&count,sizeof(int),1,fp); fclose(fp); } else{ fread(&count,sizeof(int),1,fp); count++; rewind(fp); fwrite(&count,sizeof(int),1,fp); fclose(fp); } fp = fopen("info.dat", "a+b"); printf(" Please enter name of student: "); scanf("%s",name); getchar(); printf("Please enter gender of student (M/F): "); scanf("%c",gender); printf("Please enter age of student: "); scanf("%d",age); strcat(name," "); fputs(name,fp); fputc(gender,fp); fwrite(&age,sizeof(int),1,fp); fclose(fp); }
void output(){
FILE *fp; char name[20], gender; int n, age, count;
if((fp=fopen("count.dat","r+b"))==NULL){ printf("Number of records: 0. "); }
else{ fread(&count,sizeof(int),1,fp); fclose(fp); printf("Number of records: %d. ",count); fp=fopen("info.dat","r+b"); for(n=0; n } int main() { char ans='Y'; output(); do { readKB(); printf(" Want to add another record? (Y/N): "); } while(getche()=='Y'); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
