-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
749 lines (617 loc) · 23.4 KB
/
main.c
File metadata and controls
749 lines (617 loc) · 23.4 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
#include <stdio.h>
#include <stdlib.h>
#define DEFAULT_BORROW_LIMIT 3
#define MAX_BOOK_TITLE_LENGTH 50
#define MAX_FULL_NAME_LENGTH 30
#define ERR_MEMORY_ALLOCATION_MESSAGE "Bellek tahsisi basarisiz oldu"
#define ADDED_STUDENT_MESSAGE "Ogrenci eklendi"
#define FOUND_STUDENT_MESSAGE "Ogrenci bulundu"
#define STUDENT_NOT_FOUND_MESSAGE "Ogrenci bulunamadi"
#define BOOK_NOT_FOUND_MESSAGE "Kitap bulunamadi"
#define ADDED_BOOK_MESSAGE "Kitap basariyla eklendi"
#define UPDATED_BOOK_MESSAGE "Kitap basariyla guncellendi"
#define DELETED_BOOK_MESSAGE "Kitap basariyla silindi"
#define FOUND_BOOK_MESSAGE "Aranan kitap bulundu"
#define BORROW_LIMITED_MESSAGE "Sahip oldugunuz kitap alma limitine ulastiniz"
#define BOOK_ALREADY_ON_SHELF_MESSAGE "Kitap zaten rafta"
#define BOOK_ALREADY_BORROWED_MESSAGE "Bu kitap zaten odunc alinmis"
#define DELIVERED_BOOK "Kitap iade edildi"
#define OVERDUE_BOOK "Gecikme: %d gun | Eldeki Kitap: %d Adet\nHesaplanan Ceza: %d Puan\nToplam Ceza Puaniniz: %d\n"
#define NO_OVERDUE_BOOK "Tesekkurler zamaninda %s kitabini teslim ettiniz"
//Model Layer
typedef struct {
int day, month, year;
} date_t;
typedef struct {
int id;
char *title;
char *author;
int borrowed;
struct student_t *borrower_p;
date_t update_date;
} book_t;
typedef struct student_t {
int id;
char *full_name;
int borrow_limit;
int penalty_point;
int books_length;
book_t **books_p;
} student_t;
typedef struct {
book_t *book_p;
student_t *borrower_p;
date_t borrow_date;
} borrow_book_request_t;
typedef struct {
book_t *book_p;
date_t deliver_date;
} deliver_book_request_t;
typedef struct {
int success;
char *message;
} response_t;
typedef struct {
response_t super;
void *data_p;
int data_length;
} data_response_t;
void onEnable();
// Service Layer
response_t add_student(student_t *student_p);
data_response_t find_student_by_id(int id);
data_response_t find_max_book_holders();
response_t add_book(book_t *book_p);
response_t delete_book(int id);
data_response_t find_book_by_id(int id);
response_t borrow_book(borrow_book_request_t *request);
response_t deliver_book(deliver_book_request_t *request_p);
// UI Layer
void print_main_menu();
void print_add_book_menu();
void list_books();
void print_delete_book_menu();
void list_books_by_student();
void print_add_student_menu();
void list_students();
void list_top_students();
void print_borrow_book_menu();
void print_deliver_book_menu();
void print_rules_menu();
void continue_main_menu();
// Util Layer
int read_int_input();
char *read_string_input(int max_length);
date_t read_date_input();
int calculate_penalty_point(int borrow_duration);
int get_days_between(date_t *start_date_p, date_t *end_date_p);
void handle_response_error(response_t *response_p);
// Variables
book_t *books_p;
int books_length;
int last_insert_book_id;
student_t *students_p;
int students_length;
/*
0-50 Puan arası: 3 Kitap hakkı.
50-100 Puan arası: 1 Kitap hakkı.
100+ Puan: 0 Kitap hakkı.
*/
int main(void) {
onEnable();
print_main_menu();
return 0;
}
void onEnable() {
students_length = 0;
books_length = 0;
last_insert_book_id = 0;
}
response_t add_student(student_t *student_p) {
students_p = realloc(students_p, sizeof(student_t) * (students_length + 1));
response_t response;
if (students_p == NULL) {
response.success = 0;
response.message = ERR_MEMORY_ALLOCATION_MESSAGE;
return response;
}
student_p->id = students_length + 1;
*(students_p + students_length++) = *student_p;
response.success = 1;
response.message = ADDED_STUDENT_MESSAGE;
return response;
}
data_response_t find_student_by_id(int id) {
data_response_t response;
for (int i = 0; i < students_length; i++) {
if ((students_p + i)->id != id) continue;
response.super.success = 1;
response.super.message = FOUND_STUDENT_MESSAGE;
response.data_p = students_p + i;
response.data_length = 1;
return response;
}
response.super.success = 0;
response.super.message = STUDENT_NOT_FOUND_MESSAGE;
response.data_p = NULL;
response.data_length = 0;
return response;
}
data_response_t find_max_book_holders() {
int max_book = 0, top_students_length = 0;
for (int i = 0; i < students_length; i++) {
if ((students_p + i) -> books_length < max_book) continue;
max_book = (students_p + i) -> books_length;
if ((students_p + i)->books_length == max_book)
top_students_length++;
}
student_t **top_students_p = malloc(sizeof(void*) * top_students_length);
int student_index = 0;
for (int i = 0; i < students_length; i++) {
if ((students_p + i) -> books_length != max_book) continue;
*(top_students_p + student_index++) = students_p + i;
}
data_response_t response;
if (max_book == 0) {
response.super.success = 0;
response.super.message = STUDENT_NOT_FOUND_MESSAGE;
response.data_p = NULL;
response.data_length = 0;
return response;
}
response.super.success = 1;
response.super.message = FOUND_STUDENT_MESSAGE;
response.data_p = top_students_p;
response.data_length = top_students_length;
return response;
}
response_t add_book(book_t *book_p) {
books_p = realloc(books_p, (books_length + 1) * sizeof(book_t));
response_t response;
if (books_p == NULL) {
response.success = 0;
response.message = ERR_MEMORY_ALLOCATION_MESSAGE;
return response;
}
book_p->id = last_insert_book_id += 1;
*(books_p + books_length++) = *book_p;
response.success = 1;
response.message = ADDED_BOOK_MESSAGE;
return response;
}
response_t borrow_book(borrow_book_request_t *request_p) {
response_t response;
if (request_p->book_p == NULL) {
response.success = 0;
response.message = BOOK_NOT_FOUND_MESSAGE;
return response;
}
if (request_p->book_p->borrowed == 1) {
response.success = 0;
response.message = BOOK_ALREADY_BORROWED_MESSAGE;
return response;
}
student_t *borrower_p = request_p->borrower_p;
if (borrower_p -> borrow_limit == borrower_p -> books_length) {
response.success = 0;
response.message = BORROW_LIMITED_MESSAGE;
return response;
}
request_p->book_p->borrowed = 1;
request_p->book_p->borrower_p = borrower_p;
request_p->book_p->update_date = request_p->borrow_date;
borrower_p->books_length++;
borrower_p->books_p = realloc(borrower_p->books_p, sizeof(void*) * borrower_p->books_length);
*(borrower_p->books_p + borrower_p->books_length - 1) = request_p->book_p;
response.success = 1;
response.message = UPDATED_BOOK_MESSAGE;
return response;
}
response_t deliver_book(deliver_book_request_t *request_p) {
response_t response;
if (request_p->book_p == NULL) {
response.success = 0;
response.message = BOOK_NOT_FOUND_MESSAGE;
return response;
}
book_t *book_p = request_p->book_p;
if (book_p->borrowed == 0) {
response.success = 0;
response.message = BOOK_ALREADY_ON_SHELF_MESSAGE;
return response;
}
student_t *borrower_p = book_p->borrower_p;
int returned_book_index = -1;
for (int i = 0; i < borrower_p->books_length; i++) {
if (*(borrower_p->books_p + i) == book_p) {
*(borrower_p->books_p + i) = NULL;
returned_book_index = i;
continue;
}
if (i > returned_book_index && returned_book_index != -1)
*(borrower_p->books_p + i - 1) = *(borrower_p->books_p + i);
}
response.success = 1;
response.message = DELIVERED_BOOK;
int borrow_duration = get_days_between(&request_p->book_p->update_date,
&request_p->deliver_date);
int penalty_point = calculate_penalty_point(borrow_duration);
if (penalty_point > 0) {
borrower_p->penalty_point += penalty_point;
if (borrower_p -> penalty_point >= 100)
borrower_p -> borrow_limit = 0;
else if (borrower_p -> penalty_point >= 50)
borrower_p -> borrow_limit = 1;
else if (borrower_p -> penalty_point >= 1)
borrower_p -> borrow_limit = 2;
printf(OVERDUE_BOOK "\n", borrow_duration - 20, borrower_p->books_length,
penalty_point, borrower_p->penalty_point);
return response;
}
borrower_p->books_length -= 1;
borrower_p->books_p = realloc(borrower_p->books_p, sizeof(void *) * borrower_p->books_length);
request_p->book_p->borrowed = 0;
request_p->book_p->update_date = request_p->deliver_date;
printf(NO_OVERDUE_BOOK "\n", book_p->title);
return response;
}
response_t delete_book(int id) {
book_t *book_p = (book_t *) find_book_by_id(id).data_p;
response_t response;
if (book_p == NULL) {
response.success = 0;
response.message = BOOK_NOT_FOUND_MESSAGE;
return response;
}
free(book_p->author);
free(book_p->title);
for (int i = 0; i < books_length; i++) {
if (books_p + i <= book_p) continue;
*(books_p + i - 1) = *(books_p + i);
}
books_length--;
books_p = realloc(books_p, sizeof(book_t) * books_length);
response.success = 1;
response.message = DELETED_BOOK_MESSAGE;
return response;
}
data_response_t find_book_by_id(int id) {
data_response_t response;
for (int i = 0; i < books_length; i++) {
if ((books_p + i)->id == id) {
response.super.success = 1;
response.super.message = FOUND_BOOK_MESSAGE;
response.data_p = books_p + i;
response.data_length = 1;
return response;
}
}
response.super.success = 0;
response.super.message = BOOK_NOT_FOUND_MESSAGE;
response.data_p = NULL;
response.data_length = 0;
return response;
}
void print_main_menu() {
printf("\n\n");
printf("===============================================================\n");
printf("|| KUTUPHANE BILGI VE YONETIM SISTEMI ||\n");
printf("|| (v1.0 - Admin Paneli) ||\n");
printf("===============================================================\n");
printf("|| ||\n");
printf("|| [ KITAP ISLEMLERI ] [ OGRENCI ISLEMLERI ] ||\n");
printf("|| ||\n");
printf("|| 1. Yeni Kitap Ekle 7. Ogrenci Ekle ||\n");
printf("|| 2. Kitaplari Listele 8. Ogrencileri Listele ||\n");
printf("|| 3. Kitap Sil 9. En cok kitabi olani getir ||\n");
printf("|| 4. Ogrencinin Kitaplari Listele ||\n");
printf("|| ||\n");
printf("|| [ ODUNC ISLEMLERI ] ||\n");
printf("|| ||\n");
printf("|| 5. [->] Kitap Odunc Ver ||\n");
printf("|| 6. [<-] Kitabi Geri Al (Iade Islemi) ||\n");
printf("|| ||\n");
printf("|| [ DIGER ] ||\n");
printf("|| ||\n");
printf("|| 0. [!] Ceza ve Disiplin Politikasini Goruntule ||\n");
printf("|| -1. [X] Cikis ||\n");
printf("|| ||\n");
printf("===============================================================\n");
int input;
do {
input = read_int_input();
switch (input) {
case 1:
print_add_book_menu();
break;
case 2:
list_books();
break;
case 3:
print_delete_book_menu();
break;
case 4:
list_books_by_student();
break;
case 5:
print_borrow_book_menu();
break;
case 6:
print_deliver_book_menu();
break;
case 7:
print_add_student_menu();
break;
case 8:
list_students();
break;
case 9:
list_top_students();
break;
case 0:
print_rules_menu();
break;
case -1:
exit(0);
}
} while (input < 1 || input > 6);
}
void print_add_book_menu() {
printf("\nKitabin adini giriniz");
scanf("%c");
char *title = read_string_input(MAX_BOOK_TITLE_LENGTH);
printf("\nKitabin yazarini giriniz");
char *author = read_string_input(MAX_FULL_NAME_LENGTH);
book_t book_p = {books_length + 1, title, author, 0, NULL};
response_t response = add_book(&book_p);
handle_response_error(&response);
continue_main_menu();
}
void list_books() {
printf("\n+-------+----------------------+----------------------+------------+--------------+----------------------+\n");
printf("| %-5s | %-20s | %-20s | %-10s | %-12s | %-20s |\n", "ID", "BASLIK", "YAZAR", "DURUM", "TARIH", "SON OKUYUCU");
printf("+-------+----------------------+----------------------+------------+--------------+----------------------+\n");
for (int i = 0; i < books_length; i++) {
book_t *book_p = books_p + i;
printf("\n| %-5d | %-20.20s | %-20.20s | %-10s ", book_p->id, book_p->title, book_p->author,
book_p->borrowed == 0 ? "Rafta" : "Odunc");
if (book_p->borrower_p != NULL)
printf("| %02d/%02d/%04d | %-20.20s |", book_p->update_date.day, book_p->update_date.month, book_p->update_date.year,
book_p->borrower_p->full_name);
}
scanf("%c");
continue_main_menu();
}
void print_delete_book_menu() {
printf("\nSilmek istediginiz kitabin id'sini giriniz");
int book_id = read_int_input();
response_t response = delete_book(book_id);
handle_response_error(&response);
scanf("%c");
continue_main_menu();
}
void list_books_by_student() {
int student_id;
data_response_t student_response;
do {
printf("\nOgrencinin idsini giriniz (cikis icin -1 tuslayiniz)");
student_id = read_int_input();
student_response = find_student_by_id(student_id);
if (student_id == -1) {
print_main_menu();
return;
}
handle_response_error((response_t *) &student_response);
} while (student_response.super.success == 0 && student_id != -1);
printf("\n+-------+----------------------+----------------------+------------+--------------+----------------------+\n");
printf("| %-5s | %-20s | %-20s | %-10s | %-12s | %-20s |\n", "ID", "BASLIK", "YAZAR", "DURUM", "TARIH", "OKUYUCU");
printf("+-------+----------------------+----------------------+------------+--------------+----------------------+\n");
for (int i = 0; i < ((student_t*) student_response.data_p)->books_length; i++) {
book_t *book_p = *((student_t*) student_response.data_p)->books_p + i;
printf("\n| %-5d | %-20.20s | %-20.20s | %-10s ", book_p->id, book_p->title, book_p->author,
book_p->borrowed == 0 ? "Rafta" : "Odunc");
if (book_p->borrower_p != NULL)
printf("| %02d/%02d/%04d | %-20.20s |", book_p->update_date.day, book_p->update_date.month, book_p->update_date.year,
book_p->borrower_p->full_name);
}
scanf("%c");
continue_main_menu();
}
void print_add_student_menu() {
printf("\nOgrencinin adini soyadini giriniz");
scanf("%c");
char *full_name = read_string_input(MAX_FULL_NAME_LENGTH);
student_t student = {students_length + 1, full_name, DEFAULT_BORROW_LIMIT, 0, 0, NULL};
response_t response = add_student(&student);
handle_response_error(&response);
continue_main_menu();
}
void list_students() {
printf("\n+-------+----------------------------------+------------+--------+--------------+\n");
printf("| %-5s | %-32s | %-10s | %-6s | %-12s |\n",
"ID", "ADI SOYADI", "CEZA PUANI", "KOTA", "ALINAN KITAP");
printf("+-------+----------------------------------+------------+--------+--------------+\n");
for (int i = 0; i < students_length; i++) {
printf("| %-5d | %-32.32s | %-10d | %-6d | %-12d |\n", (students_p + i)->id, (students_p + i)->full_name,
(students_p + i)->penalty_point, (students_p + i)->borrow_limit, (students_p + i)->books_length);
}
scanf("%c");
continue_main_menu();
}
void list_top_students() {
data_response_t response = find_max_book_holders();
student_t **top_students_p = (student_t**) response.data_p;
printf("\n+-------+----------------------------------+------------+--------+--------------+\n");
printf("| %-5s | %-32s | %-10s | %-6s | %-12s |\n",
"ID", "ADI SOYADI", "CEZA PUANI", "KOTA", "ALINAN KITAP");
printf("+-------+----------------------------------+------------+--------+--------------+\n");
for (int i = 0; i < response.data_length; i++) {
printf("| %-5d | %-32.32s | %-10d | %-6d | %-12d |\n", (*(top_students_p + i))->id, (*(top_students_p + i))->full_name,
(*(top_students_p + i))->penalty_point, (*(top_students_p + i))->borrow_limit, (*(top_students_p + i))->books_length);
}
free(top_students_p);
scanf("%c");
continue_main_menu();
}
void print_borrow_book_menu() {
int student_id;
data_response_t student_response;
do {
printf("\nOgrencinin idsini giriniz (cikis icin -1 tuslayiniz)");
student_id = read_int_input();
student_response = find_student_by_id(student_id);
if (student_id == -1) {
print_main_menu();
return;
}
handle_response_error((response_t *) &student_response);
} while (student_response.super.success == 0 && student_id != -1);
int book_id;
data_response_t book_response;
do {
printf("\nKitabin idsini giriniz (cikis icin -1 tuslayiniz)");
book_id = read_int_input();
book_response = find_book_by_id(book_id);
if (book_id == -1) {
print_main_menu();
return;
}
handle_response_error((response_t *) &book_response);
} while (book_response.super.success == 0 && book_id != -1);
printf("\nOdunc alma tarihini verilen formatta giriniz (gun-ay-yil)");
date_t borrow_date = read_date_input();
borrow_book_request_t borrow_book_request = {
(book_t *) book_response.data_p,
(student_t *) student_response.data_p, borrow_date
};
response_t response = borrow_book(&borrow_book_request);
handle_response_error(&response);
scanf("%c");
continue_main_menu();
}
void print_deliver_book_menu() {
int student_id;
data_response_t student_response;
do {
printf("\nOgrencinin idsini giriniz (cikis icin -1 tuslayiniz)");
student_id = read_int_input();
student_response = find_student_by_id(student_id);
if (student_id == -1) {
print_main_menu();
return;
}
handle_response_error((response_t *) &student_response);
} while (student_response.super.success == 0 && student_id != -1);
int book_id;
data_response_t book_response;
do {
printf("\nKitabin idsini giriniz (cikis icin -1 tuslayiniz)");
book_id = read_int_input();
book_response = find_book_by_id(book_id);
if (book_id == -1) {
print_main_menu();
return;
}
handle_response_error((response_t *) &book_response);
} while (book_response.super.success == 0 && book_id != -1);
printf("\nTeslim etme tarihini verilen formatta giriniz (gun-ay-yil)");
date_t deliver_date = read_date_input();
deliver_book_request_t deliver_book_request = {(book_t *) book_response.data_p, deliver_date};
response_t response = deliver_book(&deliver_book_request);
handle_response_error(&response);
scanf("%c");
continue_main_menu();
}
void print_rules_menu() {
printf("\n");
printf("***************************************************************\n");
printf("* KUTUPHANE CEZA VE DISIPLIN YONETMELIGI *\n");
printf("***************************************************************\n");
printf("\n");
printf("MADDE 1: GECIKME CEZA PUANLARI\n");
printf("Iade tarihi gecen her materyal icin asagidaki ceza puanlari uygulanir:\n");
printf("\n");
printf(" [-] 20 - 30 gun arasi gecikme : 10 Ceza Puani\n");
printf(" [-] 31 - 45 gun arasi gecikme : 25 Ceza Puani\n");
printf(" [-] 45 gunden fazla gecikme : 50 Ceza Puani\n");
printf("\n");
printf("MADDE 2: KITAP KOTASI KISITLAMALARI\n");
printf("Ogrencinin toplam ceza puani, ayni anda uzerinde bulundurabilecegi\n");
printf("maksimum kitap sayisini (Kitap Alma Hakki) belirler:\n");
printf("\n");
printf(" [V] 0 Puan (Standart) : Ayni anda maks. 3 kitap alabilir.\n");
printf(" [!] 1 - 49 Puan (Riskli) : Ayni anda maks. 2 kitap alabilir.\n");
printf(" [!!] 50 - 99 Puan (Kisitli): Ayni anda maks. 1 kitap alabilir.\n");
printf(" [X] 100+ Puan (Bloke) : Kitap alamaz. Yonetime basvurmalidir.\n");
printf("\n");
printf("NOT: Mevcut kotaniz dolduysa, elinizdeki kitabi iade etmeden\n");
printf("yeni kitap alamazsiniz.\n");
printf("***************************************************************\n");
scanf("%c");
continue_main_menu();
}
void continue_main_menu() {
printf("\n\nAna menuye donmek icin bir tusa basiniz...");
scanf("%c");
print_main_menu();
}
int read_int_input() {
printf("\n->");
int input;
scanf("%d", &input);
return input;
}
char *read_string_input(int max_length) {
printf("\n->");
char *string = (char *) malloc(max_length * sizeof(char) + 1);
gets(string);
char *temp = string;
int length = 0;
while (*temp++ != '\0')
length++;
return realloc(string, (length + 1) * sizeof(char));
}
date_t read_date_input() {
printf("\n->");
date_t date;
scanf("%d-%d-%d", &date.day, &date.month, &date.year);
return date;
}
int calculate_penalty_point(int borrow_duration) {
int penalty_point;
if (borrow_duration > 45)
penalty_point = 50;
else if (borrow_duration > 30)
penalty_point = 25;
else if (borrow_duration > 20)
penalty_point = 10;
else penalty_point = 0;
return penalty_point;
}
int get_days_between(date_t *start_date_p, date_t *end_date_p) {
int end_day = end_date_p->day;
int start_day = start_date_p->day;
int end_month = end_date_p->month;
int start_month = start_date_p->month;
int end_year = end_date_p->year;
int start_year = start_date_p->year;
int day = end_day - start_day;
if (day < 0) {
day = end_day + 30 - start_day;
end_month -= 1;
}
int month = end_month - start_month;
if (month < 0) {
month = end_month + 12 - start_month;
end_year -= 1;
}
int year = end_year - start_year;
return day + month * 30 + year * 365;
}
void handle_response_error(response_t *response_p) {
if (response_p->success == 0) {
printf("\n\nHata: %s", response_p->message);
return;
}
printf("\n\n%s", response_p->message);
}