This repository has been archived by the owner on Jan 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDictionary Database
179 lines (169 loc) · 4.19 KB
/
Dictionary Database
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
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct node
{
char data [ 20 ] ;
char dit [ 5 ] [ 20 ] ;
int dcount ;
struct node * link ;
} ;
struct node * dic [ 26 ] ;
void add ( char * ) ;
int search ( char * ) ;
void show( ) ;
void deldict( ) ;
int main( )
{
char word [ 20 ] ;
int ch ;
int i ;
clrscr( ) ;
while ( 1 )
{
clrscr( ) ;
printf ( "\n\t\tDictionary\n" ) ;
printf ( "\n\t\t1.Add Word.\n" ) ;
printf ( "\t\t2.Search Word.\n" ) ;
printf ( "\t\t3.Show Dictionary.\n" ) ;
printf ( "\t\t4.Exit." ) ;
printf ( "\n\n\t\t Enter your Choice: ") ;
scanf ( "%d", &ch ) ;
switch ( ch )
{
case 1 :
printf ( "\nEnter any word : " ) ;
fflush ( stdin ) ;
gets ( word ) ;
add ( word ) ;
break ;
case 2 :
printf ( "\nEnter the word to be searched : " ) ;
fflush ( stdin ) ;
gets ( word ) ;
i = search ( word ) ;
if ( ! i )
printf ( "Word does not exists." ) ;
getch( ) ;
break ;
case 3 :
show( ) ;
getch( ) ;
break ;
case 4 :
deldict( ) ;
exit ( 0 ) ;
default: printf ( "\nWrong Choice" ) ;
}
}
}
void add ( char * str )
{
int i, j = toupper ( str [ 0 ] ) - 65 ;
struct node * r, * temp = dic [ j ], * q ;
char descp [ 5 ] [ 20 ], ch = 'y' ;
i = search ( str ) ;
if ( i )
{
printf ( "\nWord already exists." ) ;
getch( ) ;
return ;
}
q = ( struct node * ) malloc ( sizeof ( struct node ) ) ;
strcpy ( q -> data, str ) ;
q -> link = NULL ;
for ( i = 0 ; tolower ( ch ) == 'y' && i < 5 ; i++ )
{
fflush ( stdin ) ;
printf ( "\n\nEnter the meaning(s) : " ) ;
gets ( descp [ i ] ) ;
strcpy ( q -> dit [ i ] , descp [ i ] ) ;
if ( i != 4 )
printf ( "\nAdd more meanings (y/n) " ) ;
else
printf ( "You cannot enter more than 5 meanings." ) ;
fflush ( stdin ) ;
ch = getche( ) ;
}
q -> dcount = i ;
if ( dic [ j ] == NULL || strcmp ( dic [ j ] -> data, str ) > 0 )
{
r = dic [ j ] ;
dic [ j ] = q ;
q -> link = r ;
return ;
}
else
{
while ( temp != NULL )
{
if ( ( strcmp ( temp -> data, str ) < 0 ) && ( ( strcmp ( temp -> link -> data, str ) > 0 ) || temp -> link == NULL ) )
{
q -> link = temp -> link ;
temp -> link = q ;
return ;
}
temp = temp -> link ;
}
}
}
int search ( char *str )
{
struct node *n ;
char temp1 [ 100 ] ;
char temp2 [ 100 ] ;
int i ;
n = dic [ toupper ( str [ 0 ] ) - 65 ] ;
strcpy ( temp2, str ) ;
strupr ( temp2 ) ;
while ( n != NULL )
{
strcpy ( temp1, n -> data );
if ( strcmp ( strupr ( temp1 ), temp2 ) == 0 )
{
printf ( "\n%s\t\t%s", n -> data, n -> dit [ 0 ] ) ;
for ( i = 1 ; i < n -> dcount ; i++ )
printf ( "\n\t\t%s", n -> dit [ i ] ) ;
return 1 ;
}
n = n -> link ;
}
return 0 ;
}
void show( )
{
struct node *n ;
int i, j ;
printf ( "Word\t\tMeaning\n" ) ;
for ( i = 0 ; i <= 30 ; i++ )
printf ( "-" ) ;
for ( i = 0 ; i <= 25 ; i++ )
{
n = dic [ i ] ;
while ( n != NULL )
{
printf ( "\n%s\t\t%s", n -> data, n -> dit [ 0 ] ) ;
for ( j = 1 ; j < n -> dcount ; j++ )
printf ( "\n\t\t%s", n -> dit [ j ] ) ;
n = n -> link ;
}
}
}
void deldict( )
{
struct node *n, *t ;
int i ;
for ( i = 0 ; i <= 25 ; i++ )
{
n = dic [ i ] ;
while ( n != NULL )
{
t = n -> link ;
free ( n ) ;
n = t ;
}
}
}