From the way that your question is worded I get the impression that this is a school assignment of some sort.
Nevertheless, I am feeling in a good mood this morning, so I will offer
this (PDF) article[
^], which may, or may not help.
The code is in Java, but as you didn't specify otherwise, you should not complain.
Good luck! :)