This repository has been archived by the owner on Apr 30, 2019. It is now read-only.
/
main.c
113 lines (82 loc) · 2.46 KB
/
main.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
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
#include <stdio.h>
#include <stdlib.h>
#include "adlist.h"
adlist_t read_details_for_add_listing(void)
{
adlist_t adlist;
printf(" %s\n\n", "Hint: Use acronym for subject name "
"and don't include spaces in Book Name.");
printf(" %s\n", "Enter Details:");
printf(" %s ", "Your Name:");
scanf("%s %s", adlist.fname, adlist.lname);
printf(" %s ", "Mobile No:");
scanf("%ld", &(adlist.mobile));
printf(" %s ", "Subject:");
scanf("%s", adlist.subject);
printf(" %s ", "Book Name:");
scanf("%s", adlist.bname);
printf(" %s ", "Price:");
scanf("%d", &(adlist.price));
return adlist;
}
adlist_t read_details_for_search_listings(void)
{
adlist_t adlist;
printf(" %s\n\n", "Hint: Use acronym for subject and "
"entering 0 removes respective criteria from search.");
printf(" %s\n", "Enter Details:");
printf(" %s ", "Subject:");
scanf("%s", adlist.subject);
printf(" %s ", "Book Name:");
scanf("%s", adlist.bname);
printf(" %s ", "Maximum Price:");
scanf("%d", &(adlist.price));
return adlist;
}
const char menu[] =
" +----------------------+\n"
" | PREVIOUS YEAR BOOKS |\n"
" | MENU |\n"
" +----------------------+\n"
" | 1: Sell Books |\n"
" | 2: Search for Books |\n"
" | 9: Exit |\n"
" +----------------------+";
int main(int argc, char **argv)
{
FILE *database = fopen("adlist.txt", "a+");
int choice = 0;
/* main loop */
while (1) {
printf("%s\n", menu);
/* Read number of choice */
printf(" Enter Choice: ");
scanf("%d", &choice);
printf("\n");
adlist_t adlist;
switch (choice) {
/* Add new listing */
case 1:
adlist = read_details_for_add_listing();
add_listing(database, &adlist);
rewind(database);
break;
/* Search listing */
case 2:
adlist = read_details_for_search_listings();
search_listings(database, &adlist);
rewind(database);
break;
/* Exit programm */
case 9:
printf(" Exiting....\n");
fclose(database);
return EXIT_SUCCESS;
/* Unknown option */
default:
continue;
}
printf("\n");
}
return EXIT_SUCCESS;
}