Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- struct node{
- char word[100];
- char meaning[100];
- char example[1000];
- struct node *next;
- struct node *prev;
- }*start=NULL;
- void sort(struct node *newnode)
- {
- struct node *current,*currentprev,*temp;
- current = start;
- if(start == NULL)
- start = newnode;
- else if(start->next == NULL){
- if(strcmp(newnode->word,current->word)>0){
- current->next = newnode;
- newnode -> prev = current;
- }
- else{
- newnode->next = current;
- current->prev = newnode;
- start = newnode;
- }
- }
- else{
- while(current!=NULL){
- if(strcmp(newnode->word,current->word)<0)
- break;
- if(current->next==NULL)
- temp=current;
- current = current->next;
- }
- if(current == start){
- newnode->next = current;
- current->prev = newnode;
- start = newnode;
- }
- else if(current == NULL){
- temp->next = newnode;
- newnode->prev = temp;
- }
- else{
- currentprev = current->prev;
- currentprev->next = newnode;
- newnode->prev = currentprev;
- newnode->next = current;
- current->prev = newnode;
- }
- }
- }
- int checker(struct node *newnode)
- {
- int i=0;
- struct node *current;
- current=start;
- while(current!=NULL){
- if(strcmp(current->word,newnode->word)==0){
- i++;
- break;
- }
- current=current->next;
- }
- return i;
- }
- void insert()
- {
- struct node *newnode,*current;
- newnode=(struct node*)malloc(sizeof(struct node));
- newnode->next=NULL;
- newnode->prev=NULL;
- printf("\t Enter word: ");
- getchar();
- scanf("%[^\n]",newnode->word);
- printf("\t Enter meaning: ");
- getchar();
- scanf("%s",newnode->meaning);
- printf("\t Give an example: ");
- getchar();
- scanf("%[^\n]",newnode->example);
- int i=checker(newnode);
- if(i==0){
- sort(newnode);
- system("CLS");
- printf("\t *save successful* \n");
- char n;
- getchar();
- printf("\t 1. save another word\n");
- printf("\t 2. view recent save word\n");
- printf("\t 0. Home\n");
- printf("\t Chose an option: ");
- scanf("%c",&n);
- if(n=='0'){
- system("CLS");
- return;
- }
- else if(n=='1'){
- system("CLS");
- insert();
- }
- else if(n=='2'){
- system("CLS");
- printf("\t\t word\t\t meaning \t example ");
- printf("\n\t------------------------------------------------------------\n");
- printf("\t\t %s",newnode->word);
- printf("\t\t %s",newnode->meaning);
- printf("\t\t %s\n\n",newnode->example);
- }
- }
- else{
- system("CLS");
- printf("\t\t word Exist, can't save it \n");
- printf("\t 1. save another word\n");
- printf("\t 0. Home\n");
- char n;
- getchar();
- printf("\t Chose an option: ");
- scanf("%c",&n);
- if(n=='0'){
- system("CLS");
- return;
- }
- else if(n=='1'){
- system("CLS");
- insert();
- }
- }
- }
- void del(struct node *current)
- {
- if(current == start)
- start = current->next;
- else if(current->next == NULL)
- (current->prev)->next = NULL;
- else{
- struct node *currentprev, *currentnext;
- currentprev = current->prev;
- currentnext = current->next;
- currentprev->next = currentnext;
- currentnext->prev = currentprev;
- }
- }
- void search()
- {
- struct node *current;
- if(start==NULL){
- printf("\n\t\t No word saved for search \n");
- return;
- }
- char str[100];
- printf("\t Enter name for search : ");
- getchar();
- scanf("%[^\n]",str);
- current = start;
- int i=0;
- char n;
- while(current!=NULL){
- if(strcmp(current->word,str)==0){
- system("CLS");
- printf("\t word found \n");
- printf("\t\t word \t\t meaning \t\t example");
- printf("\n\t--------------------------------------------------------\n");
- printf("\t\t %s",current->word);
- printf("\t\t %s",current->meaning);
- printf("\t\t %s\n\n",current->example);
- i++;
- break;
- }
- current = current->next;
- }
- if(i==0){
- system("CLS");
- printf("\t\t word Not Found \n");
- return;
- }
- else{
- printf("\t 1. Delete\n");
- printf("\t 0. Home\n");
- printf("\t Chose an option : ");
- getchar();
- scanf("%c",&n);
- if(n == '1'){
- system("CLS");
- del(current);
- system("CLS");
- printf("\t\t *Delete successful* \n");
- }
- else if(n == '0'){
- system("CLS");
- return;
- }
- }
- }
- void count()
- {
- struct node *current;
- int count = 0;
- current = start;
- while(current!=NULL){
- count++;
- current = current->next;
- }
- printf("\n\t\t Total words - %d\n",count);
- }
- void select(int i)
- {
- int j=1;
- struct node *current;
- current=start;
- while(j<i){
- current=current->next;
- j++;
- }
- printf("\n");
- printf("\t\t word\t\t meaning \t\t example");
- printf("\n\t----------------------------------------------------------\n");
- printf("\t\t %s",current->word);
- printf("\t\t %s",current->meaning);
- printf("\t\t %s\n\n",current->example);
- char n;
- getchar();
- printf("\t 1. Delete\n");
- printf("\t 0. Home\n");
- printf("\t Chose an option : ");
- scanf("%c",&n);
- if(n == '1'){
- system("CLS");
- del(current);
- printf("\t\t *Delete successful* \n");
- }
- else if(n == '0'){
- system("CLS");
- return;
- }
- }
- void displayall()
- {
- if(start == NULL){
- printf("\n\t No word for display\n\n");
- return;
- }
- else{
- count();
- printf("\n");
- printf("\t serial \t words \t\t meanings \t example");
- printf("\n\t---------------------------------------------------------------------\n");
- struct node *current;
- current = start;
- int i=0;
- while(current!=NULL){
- i++;
- printf("\t %d",i);
- printf("\t\t %s",current->word);
- printf("\t\t %s",current->meaning);
- printf("\t\t %s\n",current->example);
- current = current->next;
- }
- }
- printf("\n");
- char n;
- getchar();
- printf("\t Select a word or press '0' to go home: ");
- scanf("%c",&n);
- int i=n-48;
- if(i==0){
- system("CLS");
- return;
- }
- else{
- system("CLS");
- select(i);
- }
- printf("\n");
- }
- void developer()
- {
- printf("\t\t\nThis Project is Developed By\n1. Jann0at Mimee\n2. Samanta\n\n");
- }
- void home()
- {
- char n;
- while(1){
- printf("\t ***HOME***\n");
- printf("\t 1. Save a new word\n");
- printf("\t 2. Show all words\n");
- printf("\t 3. Search a word\n");
- printf("\t 4. Developers\n");
- printf("\t 0. exit\n");
- printf("\n\t Chose an option : ");
- getchar();
- scanf("%c",&n);
- if(n=='0'){
- system("CLS");
- exit(0);
- }
- else if(n=='1'){
- system("CLS");
- insert();
- }
- else if(n=='2'){
- system("CLS");
- displayall();
- }
- else if(n=='3'){
- system("CLS");
- search();
- }
- else if(n=='4'){
- system("CLS");
- developer();
- }
- else{
- printf("\t Invalid input \n");
- }
- }
- return;
- }
- int main()
- {
- char n;
- system("CLS");
- printf("\t***ENGLISH TO ENGLISH DICTIONARY***\n\n");
- printf("\npress '1' to continue : ");
- scanf("%c",&n);
- if(n=='1'){
- printf("\n\t WELCOME \n\n");
- home();
- }
- printf("Invalid Input\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement