Thread: dictionary

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    17

    dictionary

    hi all, i am new with c. i have assigment to make a simple dictionary with c. would you please help me??? what do i have to do??
    Last edited by riris; 11-29-2011 at 08:22 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is this "siple" (simple?) dictionary supposed to be?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    17

    dictionary

    yes, simple i mean. dictionary mean, that i have to make program that can translate english word into indonesia word, and from indonesian word into english word.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Okay, what about the meaning of the words, example usage and such?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Like for example,
    Code:
    struct {
      const char *word;
      const char *meaning;
    } words[] = {
      { "do", "to perform (an act, duty, role, etc.)" },
      { "homework", "schoolwork assigned to be done outside the classroom" },
      { "myself", "you alone and no one else" },
    };
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    17
    thank for the reply. i really apreciate that. i mean a dictionary like when the user type english word, example you and press enter, then the meaning in indonesia will be shown kamu. just like google translate. but only word, not sentence. what should i do???

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The simplest way would be to have two corresponding word list files. One for English, one for the same word, in Indonesian:
    Code:
    English             Indonesian
    File EWord.txt      File Iword.txt
    =========================
    hello                halo
    music                musik
    etc.

    Make two good sized array's - calloc() the memory to allocate it. I'm thinking 50,000 words for each one would be a great starting goal.

    Your program will read in each file, putting the English words into the Ewords[][] array, and the Indonesian words into the Iwords[][] array.

    If "hello" is the 500th word in the Eword file, then "halo" needs to be the 500th word in the Iword file. If "music" is the 3,000th word in the Eword file, then "musik" should be the 3,000th word in the Iword file, etc.

    If you can work with structs, you can use Salem's suggestion, up above. Replace "meaning" with your Iword, and then you can use just a single array. In that case, your word file could be just one file, and might look like this:
    Words
    ===========
    hello halo
    music musik
    etc.

    To allow for a fast binary search for a word, you'll need to keep the word file and thus the word list (for whichever language you choose), in sorted order.

    There are word lists freely available on the internet for English - just add your Indonesian equivalent to the words file, and you'll be up and running in a short while.

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    17

    dcitornary

    Thanks mr. adak. i will try that. i hoep you can help me in the future, if i have another question. thank you so much

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Thanks, and we're here if you need us.

  10. #10
    Registered User
    Join Date
    Nov 2011
    Posts
    17
    for mr adak. i already open the file with txt extension. but i don't know how to put it inside aray??

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Post up 3 lines of text, so I can see what the format of the data file, is.

    How you put it into the array, depends on the details of that.

  12. #12
    Registered User
    Join Date
    Nov 2011
    Posts
    17

    i am confuse

    mr adak, would you please guide me how to make this dictionary??? the thing that i know in c is if else statement, for, array and string. the others is in process. so, how can i make a dictionary??

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The first thing you need to do, is to download a word list in English, and get the right word that matches with it, in Indonesian. Say this is part of your English word list:

    a <Indonesian word for "a" goes here>
    abandon <Indonesian word for "abandon" goes here>
    abandons <Indonesian word for "abandons" goes here>
    abdomen <Indonesian word for "abdomen" goes here>
    abdomens <etc.>
    abduct <etc.>
    abducted <etc.>
    abductor <etc.>
    ability <etc.>

    You could put the Indonesian word after the English word, with just a space between them. (And you could turn this around so the Indonesian word was first, and the English word was second - either way.)

    I believe this is the best way to be sure the words stay matched up as they should.

    After the word list file is made up, then the program can start. You don't need a huge word list to start - just 25 words would be fine for now.

    Then I need you to post up code to start your dictionary. It can be a simple skeleton of a program, but I need to see some code from you.

    Get that done, and it's started, OK?

  14. #14
    Registered User
    Join Date
    Nov 2011
    Posts
    17

    my script

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    main()
    {
        FILE *f_struktur;
    
        struct{
            char ind[50];
            char eng[50];
        }buku;
    
        f_struktur=fopen("E:\\Kuliah\Progtur\Tugas Besar\coba.txt","rb");
    
    
        fread(&buku,sizeof(buku),1,f_struktur);
            printf("%s %s\n",buku.ind,buku.eng);
    
        printf("\n");
        fclose(f_struktur);
    }

  15. #15
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    //add int before main()
    int main()
    {
        FILE *f_struktur;
    
    
    // You can shorten the English array to 29 letters. That is the longest
    //real (non-made up and used word in the English language.
    //Antidisestablishmentarianism <= 28 + 1 for the '\0'
        struct{
            char ind[50];
            char eng[50];
        }buku;
    
    
       //change \ and \\ in this line of text, to just /
        f_struktur=fopen("E:\\Kuliah\Progtur\Tugas Besar\coba.txt","rb");
    
    
        fread(&buku,sizeof(buku),1,f_struktur);
            printf("%s %s\n",buku.ind,buku.eng);
    
        printf("\n");
        fclose(f_struktur);
    
       //add return 0
    }
    Do you want to make an array or will this be all file based?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dictionary
    By nshekofte in forum C# Programming
    Replies: 5
    Last Post: 07-28-2011, 04:40 PM
  2. change key value of a Dictionary
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-28-2008, 08:15 PM
  3. foreach Dictionary
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-27-2008, 10:01 AM
  4. Making your own dictionary
    By Rune Hunter in forum C# Programming
    Replies: 9
    Last Post: 12-03-2006, 12:23 PM
  5. May I buy you a dictionary?
    By EvenFlow in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 10-19-2001, 12:58 PM