-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path88.1 book structure.c
More file actions
42 lines (35 loc) · 942 Bytes
/
88.1 book structure.c
File metadata and controls
42 lines (35 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<stdio.h>
#include<string.h>
struct Book {
char title[100];
char author[100];
float price;
};
typedef struct Book Book;
void input_book(Book *book) {
printf("\nPlease enter the book title: ");
fgets(book->title, 100, stdin);
book->title[strcspn(book->title, "\n")] = 0;
printf("Now, enter the book's Author: ");
fgets(book->author, 100, stdin);
book->author[strcspn(book->author, "\n")] = 0;
printf("Finally, enter the book's price in Rs: ");
scanf("%f", &(book->price));
while(getchar() != '\n');
}
void print_book(Book *book) {
printf("\n%s is written by %s, and is sold for Rs%.2f",
book->title, book->author, book->price);
}
int main() {
printf("Welcome to the Book Store\n");
Book books[3];
for (int i = 0 ; i < 3; i++) {
input_book(&books[i]);
}
printf("\n\n Here are the details of all the books:\n");
for(int i = 0 ; i < 3; i++) {
print_book(&books[i]);
}
return 0;
}