-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowBorrowedBookDetails.c
63 lines (47 loc) · 1.65 KB
/
showBorrowedBookDetails.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
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <conio.h>
#include "dataTypes.h"
#include "utilities.h"
void showBorrowedBookDetails ( char * choiceID , int counter ) {
FILE * books = fopen("books.bin", "r");
// failure check
if(books==NULL) {
perror("\a\n\nError");
getche();
return;
}
FILE * borrowedBooks = fopen("borrowed-books.bin", "r");
// failure check
if(borrowedBooks==NULL) {
perror("\a\n\nError");
getche();
return;
}
bookDataType book;
borrowedBookDataType borrowedBook;
time_t todDate;
time(&todDate);
// read from original file
while( fread(&borrowedBook,sizeof(borrowedBookDataType),1,borrowedBooks) ) {
if( strcmp(borrowedBook.ID , choiceID)==0 ) {
printf("\n\nBorrowed Book %d Details.\n",counter);
// printing book's title from bookDataType since borrowedBookDataType does not contain title
while( fread(&book,sizeof(bookDataType),1,books) ) {
if( strcmp(book.ISBN , borrowedBook.ISBN)==0 ) {
printf("\nTitle\t\t: %s", book.title);
break;
}
}
// printing rest of book details from borrowedBookDataType
printf("\nISBN\t\t: %s", borrowedBook.ISBN);
printf("\nBorrow Date\t: %s", ctime(&borrowedBook.borrowDate));
printf("Due Date\t: %s %s", ctime(&borrowedBook.dueDate) , (difftime(todDate,borrowedBook.dueDate)>=0)? "(Overdue)" : "" );
getche();
break;
}
}
fclose(books);
fclose(borrowedBooks);
}