-
Notifications
You must be signed in to change notification settings - Fork 0
/
Library_program.c
168 lines (158 loc) · 4.4 KB
/
Library_program.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
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
#include <stdio.h>
int str_add( char *dest, char *src );
int str_compare( char *dest, char *src );
int main( void )
{
char Library[100][4][100];
int order, key;
char input[100];
int i;
char input2[100];
order = 0;
printf( "\n\n\n+++++++ Welcome to the Library program. ++++++++ \n" );
printf( "++++ latest update = Tue, 26 January, 2021. ++++ \n" );
printf( "\n Type \"manual\" if you want to know the commands. \n\n\n" );
while ( 1 )
{
printf( "== Insert a command. == \n" );
printf( " command : " );
scanf( "%s", input );
if ( str_compare( input, "quit" ) )
{
printf( "\n Program exited. \n" );
return( 0 );
}
else if ( str_compare( input, "manual" ) )
{
printf( " -------------------------------------------------------------- \n" );
printf( " quit = Exit the program \n" );
printf( " add = Register a book, order : Title, Author, Publisher \n" );
printf( " list = Show the list of all books the library has. \n" );
printf( " search = Search the book with keyword. \n" );
printf( " borrow = Borrow the book. \n" );
printf( " return = Return the book you borrowed. \n" );
printf( " -------------------------------------------------------------- \n\n" );
}
else if ( str_compare( input, "list" ) )
{
printf( "\n================= LIST =================\n" );
for ( i = 0; i < order; i++ )
{
printf( "Title = %s, Author = %s, Publisher = %s, Borrowed = %s \n",
Library[i][0], Library[i][1],
Library[i][2], Library[i][3] );
}
printf( "========================================\n\n" );
}
else if ( str_compare( input, "add" ) )
{
printf( "\n=== How to add a book === \n" );
printf( "= Follow the order : \"Title\" \"Author\" \"Publisher\" \n" );
printf( "= Type _ between names instead of space bar. \n" );
printf( "= ex) Demian Hermann_Hesse Fischer_Verlag \n\n\n" );
printf( " Add : " );
scanf( "%s %s %s", Library[order][0], Library[order][1],
Library[order][2] );
Library[order][3][0] = 'n';
Library[order][3][1] = 'o';
Library[order][3][2] = '\0';
printf( " < Title : %s, Author : %s, Publisher : %s > is added in Library.\n",
Library[order][0], Library[order][1], Library[order][2] );
order++;
}
else if ( str_compare( input, "search" ) )
{
printf( "\n=== Type keyword ===\n" );
printf( "= Type one keyword : \"Title\" , \"Author\" or \"Publisher\" \n" );
printf( "= Type _ between names instead of space bar. \n" );
printf( "= ex) Hermann_Hesse \n\n\n" );
printf( " Search : " );
scanf( "%s", input2 );
for ( i = 0; i < order; i++ )
{
for ( key = 0; key < 3; key++ )
{
if ( str_compare( Library[i][key], input2 ) )
{
printf( "\n< " );
printf( "Title = %s, Author = %s, Publisher = %s ",
Library[i][0], Library[i][1], Library[i][2] );
printf( "Borrowed = %s >\n\n", Library[i][3] );
}
}
}
}
else if ( str_compare( input, "borrow" ) )
{
printf( "\n=== How to borrow a book === \n" );
printf( "= Type the title of book you want to borrow. \n" );
printf( "= Type _ between names instead of space bar. \n" );
printf( "= ex) Demian \n\n\n" );
printf( " Borrow : " );
scanf( "%s", input2 );
for ( i = 0; i < order; i++ )
{
if ( str_compare( Library[i][0], input2 ) )
{
Library[i][3][0] = 'y';
Library[i][3][1] = 'e';
Library[i][3][2] = 's';
Library[i][3][3] = '\0';
printf( " %s is borrowed! \n\n", Library[i][0] );
}
}
}
else if ( str_compare( input, "return" ) )
{
printf( "\n=== How to return your book === \n" );
printf( "= Type the title of book you want to return. \n" );
printf( "= Type _ between names instead of space bar. \n" );
printf( "= ex) Demian \n\n\n" );
printf( " Return : " );
scanf( "%s", input2 );
for ( i = 0; i < order; i++ )
{
if ( str_compare( Library[i][0], input2 ) )
{
Library[i][3][0] = 'n';
Library[i][3][1] = 'o';
Library[i][3][2] = '\0';
printf( " %s is returned! \n\n", Library[i][0] );
}
}
}
}
return( 0 );
}
int str_add( char *dest, char *src )
{
while ( *dest )
{
dest++;
}
while ( *src )
{
*dest = *src;
dest++;
src++;
}
*dest = '\0';
return( 0 );
}
int str_compare( char *dest, char *src )
{
while ( *dest )
{
if ( *dest != *src )
{
return( 0 );
}
dest++;
src++;
}
if ( *dest == '\0' && *src == '\0' )
{
return( 1 );
}
return( 0 );
}