Question

write a C program to make the dictionary USING LINKED LISTS and STORE DATA in File...

write a C program to make the dictionary USING LINKED LISTS and STORE DATA in File HANDLING..... you have to create functions
1. insert
2. delete
3. search(if we search with any letter then the words with same first letter have been shown)
4. display
6. exit
Appearance should be like proper dictionary.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code

solution

//output

//copyable code

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

struct node

{

char word[30];

struct node *nextpointer;

};

struct node *add(struct node* headnode,char n[40])

{

struct node *nnode;

nnode=(struct node*)malloc(sizeof(struct node));

strcpy(nnode->word,n);

nnode->nextpointer=NULL;

if(headnode==NULL)

{

headnode=nnode;

return headnode;

}

struct node *tempvalue=headnode;

while(tempvalue->nextpointer!=NULL)

tempvalue=tempvalue->nextpointer;

tempvalue->nextpointer=nnode;

return headnode;

}

struct node *delete(struct node *headnode,char n[40])

{

int foundvalue=0;

if(strcmp(headnode->word,n)==0)

{

foundvalue=1;

struct node *p=headnode;

headnode=headnode->nextpointer;

free(p);

}

else

{

struct node *curr=headnode->nextpointer;

struct node *prev=headnode;

while(curr!=NULL)

{

if(strcmp(curr->word,n)==0)

{

prev->nextpointer=curr->nextpointer;

free(curr);

foundvalue=1;

break;

}

prev=curr;

curr=curr->nextpointer;

}

}

if(foundvalue==0)

printf("Word not foundvalue\n");

else

printf("Word deleted successfully\n");

return headnode;

}

void search(struct node *headnode,char c)

{

struct node *tempvalue=headnode;

int cnt=0;

printf("Words in dictionary\n");

while(tempvalue!=NULL)

{

if(tempvalue->word[0]==c)

{

cnt++;

printf("%s\n",tempvalue->word);

}

tempvalue=tempvalue->nextpointer;

}

printf("\n");

if(cnt==0)

printf("No word foundvalue\n");

else

printf("Total words= %d\n",cnt);

}

void PrintList(struct node *nnode)

{

    while(nnode != NULL)

    {

        printf("%s \n",nnode->word);

       nnode= nnode->nextpointer;

   }

}

int main()

{

FILE *fpvalue;

fpvalue=fopen("dictionary.txt","r");

char name[30];

struct node *headnode=NULL;

while(fgets(name,sizeof name,fpvalue) != NULL)

{

headnode=add(headnode,name);

}

fclose(fpvalue);

while(1)

{

printf("1: Insert word in dictionary\n");

printf("2: Delete word from dictionary\n");

printf("3: Search word from dictionary \n");

printf("4: display word \n");

printf("5: Exit\n");

printf("Enter choice: ");

int n;

scanf("%d",&n);

if(n==1)

{

printf("Enter the word: ");

char n[30];

scanf("%s",n);

headnode=add(headnode,n);

printf("Word added successfully\n");

}

else if(n==2)

{

printf("Enter the word to delete: ");

char n[30];

scanf("%s",n);

headnode=delete(headnode,n);

}

else if(n==3)

{

printf("Enter the starting letter of the word: ");

char ch;

scanf(" %c",&ch);

search(headnode,ch);

}

else if(n==4)

{

printf("Enter the display word: ");

PrintList(headnode);

}

else if(n==5)

{

FILE *f;

f=fopen("dictionary.txt","w");

struct node *tempvalue=headnode;

while(tempvalue!=NULL)

{

fputs(strcat(tempvalue->word,"\n"),f);

tempvalue=tempvalue->nextpointer;

}

printf("Data saved in file successfully\n");

break;

}}

return 0;

}

Add a comment
Know the answer?
Add Answer to:
write a C program to make the dictionary USING LINKED LISTS and STORE DATA in File...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a C program to make the dictionary USING LINKED LISTS and STORE DATA in File HANDLING..... you have to create functions 1. insert 2. delete 3. search(if we search with any letter then the words...

    write a C program to make the dictionary USING LINKED LISTS and STORE DATA in File HANDLING..... you have to create functions 1. insert 2. delete 3. search(if we search with any letter then the words with same first letter have been shown) 4. display 6. exit Appearance should be like proper dictionary.

  • Write a program in C to make dictionary to add, delete and search words Using linked lists. MAKE THE SEARCHING IN THE pr...

    Write a program in C to make dictionary to add, delete and search words Using linked lists. MAKE THE SEARCHING IN THE program like the searching in the online dictionary(if we enter the 1 letter then it will show all the letters starting with the same number and if we enter 2 letters then it will show all the numbers starting with same two letters and so on up to the complete word.) make the following functions 1. insert 2....

  • Write a c program to make a dictionary .... we add string in file and if we search with only one ...

    write a c program to make a dictionary .... we add string in file and if we search with only one letter then print all its same first letter word and if we enter the complete name then print the only same number.....it can be done only with linked lists...

  • C program of a dictionary using linked list

    six options in the menu:Create a new dictionary.2. Add a word to a dictionary. 3. Delete a word from a dictionary. 4. Find a word in a dictionary. 5. Delete a dictionary. 6. Exit.each word represented by typedef struct Word { char** translations; struct Word* next; } Word;each dictionary represented bytypedef struct { char** languages; int numOfLanguages; Word* wordList; } Dictionary;languages will include a pointer to an array of strings so that the first word is the origin language and...

  • Problem 1 This program is about dictionaries. We want to use a dictionary to store frequency...

    Problem 1 This program is about dictionaries. We want to use a dictionary to store frequency count of each letter in a string. Write a Python program to do the following: (a) Ask the user to enter a string. Convert all letters to uppercase. Count the frequency of each letter in the string. Store the frequency counts in a dictionary. You should count letters only. Do not count any other characters such as digits and space. Display the dictionary. (b)...

  • 13inary Search Tree Using a binary search tree, you are tasked with building a dictionary program...

    13inary Search Tree Using a binary search tree, you are tasked with building a dictionary program which you can store a word with its definition. Each node of the tree will contain the word and definition. The word is what will be used as the key to sort our data. The dictionary should allow you to search for a word. If the word exist then the definition will display. You can also add words to the dictionary. For testing you...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • Write a program that employs the four letter word dictionary to check the spelling of an...

    Write a program that employs the four letter word dictionary to check the spelling of an input word (test word). You will need to save the dictionary file to a folder on your computer. For this program you will prompt the user to enter a four letter word (or four characters). Then using a loop read each word from the dictionary and compare it to the input test word. If there is a match then you have spellchecked the word....

  • Write a function to implement linked list consisting of five nodes. Store the data in the...

    Write a function to implement linked list consisting of five nodes. Store the data in the nodes in the order given below. Also, write a function to display the data stored in the implemented linked list. in C++ programming George, Paul, Ross, Joe, Elaine, Robert1 Insert three nodes in between second node and third node in the linked list that you implemented in problem 1. Store the following data in the new (inserted) nodes in the following order. (You have...

  • C Programming Language on Linux - Word Frequency Program Please write a Program in C that...

    C Programming Language on Linux - Word Frequency Program Please write a Program in C that will accept a text file name as a command-line argument via a main program that will do the following: First, read the file (first pass) and create a linked list of words (in their order of occurrence), with the frequency of each word set to 0. Then, read the file (second pass) and for each word identified, search the linked list, and when found,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT