forked from MadhavBahl/OOPS
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstructinfunVal.c
More file actions
48 lines (40 loc) · 1.25 KB
/
structinfunVal.c
File metadata and controls
48 lines (40 loc) · 1.25 KB
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
43
44
45
46
47
48
/* =========================================== */
/* ===== passing structures in functions ===== */
/* ============= (Call By Value) ============= */
/* =========================================== */
#include<stdio.h>
#include<string.h>
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
};
void displayBookDetails(struct Books book, int i) {
printf("\nTitle of book %d: %s",i+1,book.title);
printf("\nAuthor of book %d: %s",i+1,book.author);
printf("\nSubject of book %d: %s",i+1,book.subject);
printf("\nBook ID of book %d: %d",i+1,book.book_id);
}
int main() {
// Declare 2 instances of structure books
struct Books book[100];
int n,i;
printf("Enter the number of books: ");
scanf("%d",&n);
// Enter the details of all books
for(i=0;i<n;i++) {
printf("Enter the title of book %d: ",i+1);
scanf("%s",book[i].title);
printf("Enter the author of book %d: ",i+1);
scanf("%s",book[i].author);
printf("Enter the subject of book %d: ",i+1);
scanf("%s",book[i].subject);
book[i].book_id = 10000+8*i;
}
// Print the details of both books
for(i=0;i<n;i++) {
displayBookDetails(book[i],i);
}
return 0;
}