Ooops, forgot to specify that the code is in the C language. But im sure you knew.