This is a simple lookup and replace.
You need a "dictionary", a list of words that match.
Our initial dictionary can be simple:
"kumusta" --> "how"
"ka" --> "you"
"ngayon" --> "now"
|
Given the sentence: "Kumusta ka ngayon?"
Apply your dictionary, word for word, and you'll get: "How you now?"
That's a pretty good approximation of what a native English speaker would say: "How are you today?"
There are other things you can do to refine the translation, but that is probably enough to do your assignment. You can read more advanced stuff here:
http://wiki.tcl.tk/10262
I'm not sure exactly how your teacher wants you to use
pointers to accomplish this. There are a number of ways I can think of... The most simple would probably be to have an array of pairs -- or a pair of arrays -- that have the two sides.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
typedef struct
{
const char* tagalog;
const char* english;
}
entry_t;
const entry_t[] =
{
{ "kumusta", "how" },
{ "ka", "you" },
{ "ngayon", "now" }
};
|
You will have to do some processing on your input also:
1. convert everything to lowercase
2. tokenize on whitespaces (to get individual words)
3. watch out for trailing punctuation
4. find the word and write the matching word in the output string
5. don't forget the punctuation
6. capitalize the first word in the final output string
Good luck!