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??
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.
What is this "siple" (simple?) dictionary supposed to be?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
Okay, what about the meaning of the words, example usage and such?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
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???
The simplest way would be to have two corresponding word list files. One for English, one for the same word, in Indonesian:
etc.Code:English Indonesian File EWord.txt File Iword.txt ========================= hello halo music musik
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.
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
Thanks, and we're here if you need us.
for mr adak. i already open the file with txt extension. but i don't know how to put it inside aray??
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.
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??
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?
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); }
Do you want to make an array or will this be all file based?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 }