Thank you VERY much ocicat for the advice and the help.
As for the second post, I've already done that in perl.
I want to achieve it in C (as well as some other simple scripts) just for the excercise and the excitement. I see that many simple scripts can be a hell to achieve with C, but they are a great learning experience. No pain, no gain after all.