You might want to cosider doing this in Perl. It will be far easier than in C/C++.