In: Computer Science
Answer:
Code:
#include <stdio.h>
struct Book {
char author[20];
char title[40];
char publisher[20];
int year;
int isbn;
char genre[5];
float price;
};
int main(){
struct Book books[100];
int count = 0;
do {
int isbn;
printf("\nEnter ISBN (or 0 to stop): ");
scanf("%d", &isbn);
if (isbn == 0)
break;
books[count].isbn = isbn;
fflush(stdin);
printf("Enter author: ");
scanf("%[^\n]%*c", &books[count].author);
printf("Enter title: ");
scanf("%[^\n]%*c", &books[count].title);
printf("Enter publisher: ");
scanf("%[^\n]%*c", &books[count].publisher);
printf("Enter year: ");
scanf("%d", &books[count].year);
fflush(stdin);
printf("Enter genre: ");
scanf("%[^\n]%*c", &books[count].genre);
printf("Enter price: ");
scanf("%f", &books[count].price);
count += 1;
}
while(1);
// remove lines C1 and C2 to print entered book details
/*************************************** C1 ************************************************
for(int i = 0; i < count; i++){
printf("\nBook %d\nISBN: %d\nAuthor: %s", i+1, books[i].isbn, books[i].author);
printf("\nTitle: %s\nPublisher: %s", books[i].title, books[i].publisher);
printf("\nGenre: %s\nYear: %d\nPrice: %f\n", books[i].genre, books[i].year, books[i].price);
}
*************************************** C2 ************************************************/
return 0;
}
Output:
If you want to print book details:
Code:
Output: