-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathstructinfun.c
52 lines (43 loc) · 1.31 KB
/
structinfun.c
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
49
50
51
52
/* =========================================== */
/* ===== passing structures in functions ===== */
/* ========== (Call By Reference) ============ */
/* =========================================== */
#include<stdio.h>
#include<string.h>
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
};
void inputBookDetails(struct Books *book, int i) {
printf("Enter the title of book %d: ",i+1);
scanf("%s",book->title);
printf("Enter the author of book %d: ",i+1);
scanf("%s",book->author);
printf("Enter the subject of book %d: ",i+1);
scanf("%s",book->subject);
book->book_id = 10000+8*i;
}
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++) {
inputBookDetails(&book[i],i);
}
// Print the details of both books
for(i=0;i<n;i++) {
displayBookDetails(&book[i],i);
}
return 0;
}