Advertisement
erfanul007

Project Dictionary

Dec 9th, 2018
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.05 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. struct node{
  6. char word[100];
  7. char meaning[100];
  8. char example[1000];
  9. struct node *next;
  10. struct node *prev;
  11. }*start=NULL;
  12.  
  13.  
  14. void sort(struct node *newnode)
  15. {
  16. struct node *current,*currentprev,*temp;
  17.  
  18. current = start;
  19.  
  20. if(start == NULL)
  21. start = newnode;
  22.  
  23. else if(start->next == NULL){
  24.  
  25. if(strcmp(newnode->word,current->word)>0){
  26. current->next = newnode;
  27. newnode -> prev = current;
  28. }
  29.  
  30. else{
  31. newnode->next = current;
  32. current->prev = newnode;
  33. start = newnode;
  34. }
  35. }
  36.  
  37. else{
  38. while(current!=NULL){
  39. if(strcmp(newnode->word,current->word)<0)
  40. break;
  41. if(current->next==NULL)
  42. temp=current;
  43. current = current->next;
  44. }
  45.  
  46. if(current == start){
  47. newnode->next = current;
  48. current->prev = newnode;
  49. start = newnode;
  50. }
  51.  
  52. else if(current == NULL){
  53. temp->next = newnode;
  54. newnode->prev = temp;
  55. }
  56.  
  57. else{
  58. currentprev = current->prev;
  59. currentprev->next = newnode;
  60. newnode->prev = currentprev;
  61. newnode->next = current;
  62. current->prev = newnode;
  63. }
  64. }
  65.  
  66. }
  67.  
  68. int checker(struct node *newnode)
  69. {
  70. int i=0;
  71. struct node *current;
  72. current=start;
  73. while(current!=NULL){
  74. if(strcmp(current->word,newnode->word)==0){
  75. i++;
  76. break;
  77. }
  78. current=current->next;
  79. }
  80. return i;
  81. }
  82.  
  83. void insert()
  84. {
  85. struct node *newnode,*current;
  86. newnode=(struct node*)malloc(sizeof(struct node));
  87. newnode->next=NULL;
  88. newnode->prev=NULL;
  89.  
  90. printf("\t Enter word: ");
  91. getchar();
  92. scanf("%[^\n]",newnode->word);
  93.  
  94. printf("\t Enter meaning: ");
  95. getchar();
  96. scanf("%s",newnode->meaning);
  97.  
  98. printf("\t Give an example: ");
  99. getchar();
  100. scanf("%[^\n]",newnode->example);
  101.  
  102. int i=checker(newnode);
  103. if(i==0){
  104. sort(newnode);
  105. system("CLS");
  106. printf("\t *save successful* \n");
  107. char n;
  108. getchar();
  109. printf("\t 1. save another word\n");
  110. printf("\t 2. view recent save word\n");
  111. printf("\t 0. Home\n");
  112. printf("\t Chose an option: ");
  113. scanf("%c",&n);
  114. if(n=='0'){
  115. system("CLS");
  116. return;
  117. }
  118. else if(n=='1'){
  119. system("CLS");
  120. insert();
  121. }
  122. else if(n=='2'){
  123. system("CLS");
  124. printf("\t\t word\t\t meaning \t example ");
  125. printf("\n\t------------------------------------------------------------\n");
  126. printf("\t\t %s",newnode->word);
  127. printf("\t\t %s",newnode->meaning);
  128. printf("\t\t %s\n\n",newnode->example);
  129. }
  130. }
  131. else{
  132. system("CLS");
  133. printf("\t\t word Exist, can't save it \n");
  134. printf("\t 1. save another word\n");
  135. printf("\t 0. Home\n");
  136. char n;
  137. getchar();
  138. printf("\t Chose an option: ");
  139. scanf("%c",&n);
  140. if(n=='0'){
  141. system("CLS");
  142. return;
  143. }
  144. else if(n=='1'){
  145. system("CLS");
  146. insert();
  147. }
  148. }
  149. }
  150.  
  151.  
  152. void del(struct node *current)
  153. {
  154. if(current == start)
  155. start = current->next;
  156.  
  157. else if(current->next == NULL)
  158. (current->prev)->next = NULL;
  159.  
  160. else{
  161. struct node *currentprev, *currentnext;
  162. currentprev = current->prev;
  163. currentnext = current->next;
  164. currentprev->next = currentnext;
  165. currentnext->prev = currentprev;
  166. }
  167. }
  168.  
  169. void search()
  170. {
  171. struct node *current;
  172. if(start==NULL){
  173. printf("\n\t\t No word saved for search \n");
  174. return;
  175. }
  176.  
  177. char str[100];
  178. printf("\t Enter name for search : ");
  179. getchar();
  180. scanf("%[^\n]",str);
  181. current = start;
  182.  
  183. int i=0;
  184. char n;
  185.  
  186. while(current!=NULL){
  187. if(strcmp(current->word,str)==0){
  188. system("CLS");
  189. printf("\t word found \n");
  190. printf("\t\t word \t\t meaning \t\t example");
  191. printf("\n\t--------------------------------------------------------\n");
  192. printf("\t\t %s",current->word);
  193. printf("\t\t %s",current->meaning);
  194. printf("\t\t %s\n\n",current->example);
  195. i++;
  196. break;
  197. }
  198.  
  199. current = current->next;
  200. }
  201.  
  202. if(i==0){
  203. system("CLS");
  204. printf("\t\t word Not Found \n");
  205. return;
  206. }
  207.  
  208. else{
  209. printf("\t 1. Delete\n");
  210. printf("\t 0. Home\n");
  211. printf("\t Chose an option : ");
  212.  
  213. getchar();
  214. scanf("%c",&n);
  215.  
  216. if(n == '1'){
  217. system("CLS");
  218. del(current);
  219. system("CLS");
  220. printf("\t\t *Delete successful* \n");
  221. }
  222. else if(n == '0'){
  223. system("CLS");
  224. return;
  225. }
  226. }
  227.  
  228. }
  229.  
  230.  
  231. void count()
  232. {
  233. struct node *current;
  234. int count = 0;
  235. current = start;
  236.  
  237. while(current!=NULL){
  238. count++;
  239. current = current->next;
  240. }
  241. printf("\n\t\t Total words - %d\n",count);
  242. }
  243.  
  244.  
  245. void select(int i)
  246. {
  247. int j=1;
  248. struct node *current;
  249. current=start;
  250. while(j<i){
  251. current=current->next;
  252. j++;
  253. }
  254. printf("\n");
  255. printf("\t\t word\t\t meaning \t\t example");
  256. printf("\n\t----------------------------------------------------------\n");
  257. printf("\t\t %s",current->word);
  258. printf("\t\t %s",current->meaning);
  259. printf("\t\t %s\n\n",current->example);
  260.  
  261. char n;
  262. getchar();
  263. printf("\t 1. Delete\n");
  264. printf("\t 0. Home\n");
  265. printf("\t Chose an option : ");
  266. scanf("%c",&n);
  267. if(n == '1'){
  268. system("CLS");
  269. del(current);
  270. printf("\t\t *Delete successful* \n");
  271. }
  272. else if(n == '0'){
  273. system("CLS");
  274. return;
  275. }
  276. }
  277.  
  278.  
  279. void displayall()
  280. {
  281. if(start == NULL){
  282. printf("\n\t No word for display\n\n");
  283. return;
  284. }
  285.  
  286. else{
  287. count();
  288. printf("\n");
  289. printf("\t serial \t words \t\t meanings \t example");
  290. printf("\n\t---------------------------------------------------------------------\n");
  291. struct node *current;
  292. current = start;
  293. int i=0;
  294. while(current!=NULL){
  295. i++;
  296.  
  297. printf("\t %d",i);
  298. printf("\t\t %s",current->word);
  299. printf("\t\t %s",current->meaning);
  300. printf("\t\t %s\n",current->example);
  301.  
  302. current = current->next;
  303. }
  304. }
  305. printf("\n");
  306. char n;
  307. getchar();
  308. printf("\t Select a word or press '0' to go home: ");
  309. scanf("%c",&n);
  310. int i=n-48;
  311. if(i==0){
  312. system("CLS");
  313. return;
  314. }
  315. else{
  316. system("CLS");
  317. select(i);
  318. }
  319. printf("\n");
  320. }
  321.  
  322. void developer()
  323. {
  324. printf("\t\t\nThis Project is Developed By\n1. Jann0at Mimee\n2. Samanta\n\n");
  325. }
  326.  
  327. void home()
  328. {
  329. char n;
  330. while(1){
  331. printf("\t ***HOME***\n");
  332. printf("\t 1. Save a new word\n");
  333. printf("\t 2. Show all words\n");
  334. printf("\t 3. Search a word\n");
  335. printf("\t 4. Developers\n");
  336. printf("\t 0. exit\n");
  337. printf("\n\t Chose an option : ");
  338. getchar();
  339. scanf("%c",&n);
  340. if(n=='0'){
  341. system("CLS");
  342. exit(0);
  343. }
  344. else if(n=='1'){
  345. system("CLS");
  346. insert();
  347. }
  348. else if(n=='2'){
  349. system("CLS");
  350. displayall();
  351. }
  352.  
  353. else if(n=='3'){
  354. system("CLS");
  355. search();
  356. }
  357. else if(n=='4'){
  358. system("CLS");
  359. developer();
  360. }
  361. else{
  362. printf("\t Invalid input \n");
  363. }
  364. }
  365. return;
  366. }
  367.  
  368.  
  369. int main()
  370. {
  371. char n;
  372. system("CLS");
  373. printf("\t***ENGLISH TO ENGLISH DICTIONARY***\n\n");
  374. printf("\npress '1' to continue : ");
  375. scanf("%c",&n);
  376. if(n=='1'){
  377. printf("\n\t WELCOME \n\n");
  378. home();
  379. }
  380. printf("Invalid Input\n");
  381. return 0;
  382. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement