#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    HELP on making a dictionary program in c language!!!


    Hello guys.
    I got a group assignment to make a dictionary program in c language, but my entire class just started learning c language at school so no one has solved this problem yet... :(
    Could anyone please help me on making this program??

    Okay so the goal is to make a dictionary program with these commands:
    1.) :add, 2.) :print , 3.) :delete, 4.):save, 5.):load and 6.):quit.
    An entry contains a word and its definition. It is assumed that one word has only one definition.


    ### Command definition ###

    :add or :a [Word]
    Add an entry of the following word. If the word is already in the dictionary, the program prompts the user whether or not the existing word would be overwritten or not. If the initial character of the word is lower case, replace it with its capital.

    :print or :p ([Word])
    If a word is not following, print all the entries in the dictionary. When a word is given after “:print” or “:p”, just print the word and its definition.

    :delete or :d [Word]
    Delete the entry of the given word.

    :save or :s [Filename]
    Save the current dictionary to a text file for later use.

    :load or :l [Filename]
    Load a dictionary from the text file. It overwrites the current dictionary.

    :quit or :q
    Quit the program immediately.
    Your objective is to make the program, which behaves exactly the same as the sample below. The blue letters are user inputs.


    What I wrote below is sample for this program.
    ALL BLUE WORDS are things that we need to write on program
    and ALL BLACK ONES are what the program should show.
    *[ENTER] is hitting enter, not writing.

    > ./linkedDict
    dict~
    ### Adding "Apple" to the dictionary ###
    :add Apple[ENTER]
    Enter the definition: Fruit with red or yellow or green skin and sweet to tart crisp whitish
    flesh.[ENTER]

    ### "Apple" is added ###


    dict~
    :print[ENTER]
    Apple: Fruit with red or yellow or green skin and sweet to tart crisp whitish flesh.
    Book: A written or printed work consisting of pages glued or sewn together along one side and bound in covers.
    Dictionary: A reference book containing an alphabetical list of words, with information given for each word.

    dict~
    :p dictionary[ENTER]
    Dictionary: A reference book containing an alphabetical list of words, with information given for each word.

    dict~
    :delete dictionary[ENTER]
    ### Deleting "Dictionary" ###
    dictionary: A reference book containing an alphabetical list of words, with information
    given for each word.
    ### "Dictionary" is deleted ###


    dict~
    :p
    Apple: Fruit with red or yellow or green skin and sweet to tart crisp whitish flesh.
    Book: A written or printed work consisting of pages glued or sewn together along one side
    and bound in covers.

    dict~
    :save dict.txt
    ### The current dictionary was saved to "dict.txt" ###

    dict~
    :d dictionary[ENTER]
    "Dictionary" is not found in the dictionary.

    dict~
    :a Apple[ENTER]
    ### "Apple" is already in the dictionary ###
    ### If you want to overwrite the definition, enter below, otherwise just hit ENTER. ###
    Enter the definition: Apple Inc. is an American multinational corporation headquartered in Cupertino, California.[ENTER]
    ### "Apple" is modified ###

    dict~
    :a book[ENTER]
    ### "Book" is already in the dictionary ###
    ### If you want to overwrite the definition, enter below, otherwise just hit ENTER. ###
    Enter the definition: [ENTER]
    ### "Book" is not modified ###

    dict~
    :s[ENTER]
    Apple: Apple Inc. is an American multinational corporation headquartered in Cupertino,
    California.
    Book: A written or printed work consisting of pages glued or sewn together along one side
    and bound in covers.

    dict~
    :load dict.txt
    ### A dictionary was loaded from "dict.txt" ###


    dict~
    :print
    Apple: Fruit with red or yellow or green skin and sweet to tart crisp whitish flesh.
    Book: A written or printed work consisting of pages glued or sewn together along one side
    and bound in covers.

    dict~
    :quit
    Quitting the dictionary program…
    ### Sample End ###

    Since my group members are not familiar with c language, we haven't even begun writing anything :(
    Please please please help me on making this program!!!!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    68
    Rep Power
    0
    okay,
    So your requirements like

    1.) :add, 2.) print , 3.) :delete, 4.):save, 5.):load and 6.):quit.

    can be added in functions.

    each function will do its task.
    eg: add(char * word);
    delete(char * word);

    so you will need atleast 6 functions and call them accordingly in main.


    You can store your dictionary in a text file.To retrieve data you need to use file handling.

    thats a rough idea from where you can actually start the development.
  4. #3
  5. No Profile Picture
    Still Learning
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Montreal, Canada
    Posts
    55
    Rep Power
    40
    First thing you are going to have to do is read from a file or from the console a line a t a time. search for "read line in c" and look at the results. You should find several examples like this.

    http://www.daniweb.com/software-development/c/code/216411/reading-a-file-line-by-line#

    It may not given you the exact answer but it will give you code that you can run an experiment with.
  6. #4
  7. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,117
    Rep Power
    1803
    We need to be clear perhaps what the scope of this task is.

    In Computer Science the term "dictionary" has specific meaning as an alternative name for an associative array; you could naturally implement your dictionary using an associative array, but I suspect that in this case that is not a requirement and perhaps too advanced and that the term "dictionary" is used in its general sense of a "lexicon". Is that the case?

    It is unfortunate perhaps that you are not learning C++; the C++ standard library includes an associative array container that would make this task trivial.

    The most appropriate solution will depend on what it is you have been taught, since the point of the assignment is to demonstrate learning. So the solution should be constructed from what you know or have at least covered in class. Since we don't know what that is, and solution offered here is likely to extend beyond that scope and you may be penalised that even if it is technically a better solution (the point being that it will not be your solution, and thus demonstrate nothing about what you have learned.

    Not only do you need to show fair effort therefore, you need to give some guidance regarding acceptable techniques for solution.

IMN logo majestic logo threadwatch logo seochat tools logo