| Odrimar (1) | |||
|
Hey everyone! I want to make a program that acts something like a dictionary. Meaning: i have a file dictionary.txt with words and their definitions each on one line like this: Dog A domestic animal bla bla bla. Bedroom A room in which you sleep. and so on... and i want my program to do the following: 1.When i give a word i want it to return the definition of that word, or if the word is not in dictionary.txt i want it to display a message like "the word is not there". 2.I want to add words to the dictionary with their meanings so that if i want to search for this new added word later with function 1. it will display the meaning. The code i got so far is:
The problems i have so far are: (and i know that maybe the code i got is a little messed up and unorganized with a lot of memory allocated for nothing but anyways) 1. If i call the functions in the order that i called them in main like citire() then cauta() then adauga() after i search for the given word and the program prints its meaning, i get "Introduceti cuvantul ce doriti sa fie adaugat: Introduceti o definitie pentru cuvantul adaugat: ". I mean the program is not waiting for me to type the word and then print "introduceti o definitie" and then type the definition. It just prints both lines and read only one word that i give. 2.If i call the functions in other order like citire() adauga() cauta() the program works just fine. But i want it, after every added word and its meaning from adauga() to read the hole .txt file again so that i can search for the words later. So i want to call them like this citire() adauga() citire() cauta() but after i add the word and the defintion the program just stops and in my dictionary.txt i get a hole copy of what is already written in there plus alot of blank spaces and new lines. 3.I also wanted to make a menu for the program like : 1. Search for a word 2. Add a word 3. Show dictionary 4. Exit Choose the number: and i did it something like this: int z; citire(); printf("1. Search for a word"); . . . scanf("%d",z); if(z==1) cauta(); . . the problem here was that when i pressed 1 and hit enter it just gave me a "Program has stopped working". And when i tried to debug it told me something like Access violation error(Segmentation fault) or something like that. If anyone can tell me what did i do wrong please do. Looking forward to your replies. Thanks in advance. | |||
|
|
|||