Advertisement
erfanul007

Dictionary

Dec 9th, 2018
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.40 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("%s",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 edit(struct node *current)
  170. {
  171. del(current);
  172.  
  173. char n;
  174.  
  175. printf("1. Change word\n");
  176. printf("2. Skip\n");
  177. printf("\nChose an option : ");
  178. getchar();
  179. scanf("%c",&n);
  180. system("CLS");
  181. if(n == '1'){
  182. printf("edit word : ");
  183. getchar();
  184. scanf("%s",current->word);
  185. }
  186. system("CLS");
  187. printf("1. Change meaning\n");
  188. printf("2. Skip\n");
  189. printf("\nChose an option : ");
  190. getchar();
  191. scanf("%c",&n);
  192. system("CLS");
  193. if(n == '1'){
  194. printf("edit meaning: ");
  195. getchar();
  196. scanf("%s",current->meaning);
  197. }
  198. system("CLS");
  199. printf("1. Change example\n");
  200. printf("2. Skip\n");
  201. printf("\nChose an option: ");
  202. getchar();
  203. scanf("%c",&n);
  204. system("CLS");
  205. if(n == '1'){
  206. printf("edit example: ");
  207. getchar();
  208. scanf("%[^\n]",current->example);
  209. }
  210. system("CLS");
  211. current->next = NULL;
  212. current->prev = NULL;
  213. sort(current);
  214.  
  215. }
  216.  
  217.  
  218. void search()
  219. {
  220. struct node *current;
  221. if(start==NULL){
  222. printf("\n\t\t No word saved for search \n");
  223. return;
  224. }
  225.  
  226. char str[100];
  227. printf("\t Enter name for search : ");
  228. getchar();
  229. scanf("%s",str);
  230. current = start;
  231.  
  232. int i=0;
  233. char n;
  234.  
  235. while(current!=NULL){
  236. if(strcmp(current->word,str)==0){
  237. system("CLS");
  238. printf("\t word found \n");
  239. printf("\t\t word \t\t meaning \t\t example");
  240. printf("\n\t--------------------------------------------------------\n");
  241. printf("\t\t %s",current->word);
  242. printf("\t\t %s",current->meaning);
  243. printf("\t\t %s\n\n",current->example);
  244. i++;
  245. break;
  246. }
  247.  
  248. current = current->next;
  249. }
  250.  
  251. if(i==0){
  252. system("CLS");
  253. printf("\t word Not Found \n");
  254. return;
  255. }
  256.  
  257. else{
  258. printf("\t 1. Delete\n");
  259. printf("\t 2. edit\n");
  260. printf("\t 0. Home\n");
  261. printf("\t Chose an option : ");
  262.  
  263. getchar();
  264. scanf("%c",&n);
  265.  
  266. if(n == '1'){
  267. system("CLS");
  268. del(current);
  269. system("CLS");
  270. printf("\t *Delete successful* \n");
  271. }
  272. else if(n == '2'){
  273. system("CLS");
  274. edit(current);
  275. system("CLS");
  276. printf("\t *Edit successful* \n");
  277. }
  278. else if(n == '0'){
  279. system("CLS");
  280. return;
  281. }
  282. }
  283.  
  284. }
  285.  
  286.  
  287. void count()
  288. {
  289. struct node *current;
  290. int count = 0;
  291. current = start;
  292.  
  293. while(current!=NULL){
  294. count++;
  295. current = current->next;
  296. }
  297. printf("\n\t\t Total words - %d\n",count);
  298. }
  299.  
  300.  
  301. void select(int i)
  302. {
  303. int j=1;
  304. struct node *current;
  305. current=start;
  306. while(j<i){
  307. current=current->next;
  308. j++;
  309. }
  310. printf("\n");
  311. printf("\t\t word\t\t meaning \t\t example");
  312. printf("\n\t----------------------------------------------------------\n");
  313. printf("\t\t %s",current->word);
  314. printf("\t\t %s",current->meaning);
  315. printf("\t\t %s\n\n",current->example);
  316.  
  317. char n;
  318. getchar();
  319. printf("\t 1. Delete\n");
  320. printf("\t 2. Edit\n");
  321. printf("\t 0. Home\n");
  322. printf("\t Chose an option : ");
  323. scanf("%c",&n);
  324. if(n == '1'){
  325. system("CLS");
  326. del(current);
  327. system("CLS");
  328. printf("\t *Delete successful* \n");
  329. }
  330. else if(n=='2'){
  331. system("CLS");
  332. edit(current);
  333. system("CLS");
  334. printf("\t *Edit successful* \n");
  335. }
  336. else if(n == '0'){
  337. system("CLS");
  338. return;
  339. }
  340. }
  341.  
  342.  
  343. void displayall()
  344. {
  345. if(start == NULL){
  346. printf("\n\t No word for display\n\n");
  347. return;
  348. }
  349.  
  350. else{
  351. count();
  352. printf("\n");
  353. printf("\t serial \t words \t\t meanings \t example");
  354. printf("\n\t---------------------------------------------------------------------\n");
  355. struct node *current;
  356. current = start;
  357. int i=0;
  358. while(current!=NULL){
  359. i++;
  360.  
  361. printf("\t %d",i);
  362. printf("\t\t %s",current->word);
  363. printf("\t\t %s",current->meaning);
  364. printf("\t\t %s\n",current->example);
  365.  
  366. current = current->next;
  367. }
  368. }
  369. printf("\n");
  370. char n;
  371. getchar();
  372. printf("\t Select a word or press '0' to go home: ");
  373. scanf("%c",&n);
  374. int i=n-48;
  375. if(i==0){
  376. system("CLS");
  377. return;
  378. }
  379. else{
  380. system("CLS");
  381. select(i);
  382. }
  383. printf("\n");
  384. }
  385.  
  386. void developer()
  387. {
  388. printf("\t\t\nThis Project is Developed By\n1. Jann0at Mimee\n2. Samanta\n\n");
  389. }
  390.  
  391. void home()
  392. {
  393. char n;
  394. while(1){
  395. printf("\t ***HOME***\n");
  396. printf("\t 1. Save a new word\n");
  397. printf("\t 2. Show all words\n");
  398. printf("\t 3. Search a word\n");
  399. printf("\t 4. Developers\n");
  400. printf("\t 0. exit\n");
  401. printf("\n\t Chose an option : ");
  402. getchar();
  403. scanf("%c",&n);
  404. if(n=='0'){
  405. system("CLS");
  406. exit(0);
  407. }
  408. else if(n=='1'){
  409. system("CLS");
  410. insert();
  411. }
  412. else if(n=='2'){
  413. system("CLS");
  414. displayall();
  415. }
  416.  
  417. else if(n=='3'){
  418. system("CLS");
  419. search();
  420. }
  421. else if(n=='4'){
  422. system("CLS");
  423. developer();
  424. }
  425. else{
  426. printf("\t Invalid input \n");
  427. }
  428. }
  429. return;
  430. }
  431.  
  432.  
  433. int main()
  434. {
  435. char n;
  436. system("CLS");
  437. printf("\t***ENGLISH TO ENGLISH DICTIONARY***\n\n");
  438. printf("\npress '1' to continue : ");
  439. scanf("%c",&n);
  440. if(n=='1'){
  441. system("CLS");
  442. printf("\n\t WELCOME \n\n");
  443. home();
  444. }
  445. printf("Invalid Input\n");
  446. return 0;
  447. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement