-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdriver.c
160 lines (131 loc) · 3.16 KB
/
driver.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "header.h"
int length,top;
int main()
{
char key[100];
char m[500];
struct trienode *root;
int ch=1;
root=getnode();
struct meaning *head= NULL;
file_to_dict(root,&head);
while(ch!=0)
{
printf("\n\n---------------------------------------------------------------------------------------------------");
printf("\n1. Insert");
printf("\n2. Display");
printf("\n3. Search meaning");
printf("\n4. Delete word");
printf("\n5. Display prefix");
printf("\n6. Display meaning-synonyms");
printf("\n7. Display synonyms of a word\n");
int y=scanf("%d",&ch);
if(y!=1)
return 0;
switch(ch)
{
case 1: {
input:
printf("Enter the string: ");
int x=scanf(" %[^\n]s",key);
int check=1;
for(int i=0;key[i]!='\0';i++)
{
if(!isalpha(key[i]))
{
check=0;
printf("Enter alphabetic string!!\n");
break;
}
}
if(check==0)
goto input;
if(x!=1)
break;
printf("Enter the meaning: ");
x=scanf(" %[^\n]s",m);
if(x!=1)
break;
insert(root, key,m);
int result=check_meaning(head,m);
//printf("word is %s and check is %d",m,result);
if(result!=0)
insert_synonym(&head,m,key);
else
insert_meaning(&head,key,m);
add_to_file(key,m);
}break;
case 2: {length=0;
printf("The words stored in the dictionary are: ");
display(root);
}break;
case 3: { printf("Enter the string for search: ");
int x=scanf(" %[^\n]%*c", key);
if(x!=1)
break;
char search_value[500];
strcpy(search_value,search(root, key));
if(strcmp(search_value,"Not Found")!=0)
{
printf("\nMeaning is: %s",search_value);
}
else
printf("%s",search_value);
}break;
case 4: {
printf("Enter the word for deletion..\n");
int x=scanf("%s",key);
if(x!=1)
break;
top=0;
char search_value[500];
strcpy(search_value,search(root, key));
if(strcmp(search_value,"Not Found")!=0)
{ delete_trie(root,key);
del_thes(head,key,search_value);
del_word(key);
}
else
printf("\n%s",search_value);
}
break;
case 5: {
length=0;
printf("Enter the string for search ..\n");
int x=scanf("%s",key);
if(x!=1)
break;
search_pre(root, key);
}break;
case 6: {
if(head!=NULL)
display_pairs(head);
}break;
case 7: {
printf("Enter the string for search: ");
int x=scanf(" %[^\n]s",key);
if(x!=1)
break;
char search_value[500];
strcpy(search_value,search(root, key));
if(strcmp(search_value,"Not Found")!=0)
{
find_syn(head,search_value,key);
}
else
printf("%s",search_value);
}break;
default: {
ch=0;
destroy(&head);
destroy_trie(&root);
//exit(0);
}
}
}
return 0;
}