How you do this is going to depend on what libraries you have available in your C package! So I can't give you the code...
The basic idea is pretty simple - there is an article here which does it, albeit in .NET which you can't actually use becasue it doesn't support C:
Calculate and Draw Moon Phase[
^]
The code should give you a basic mechanism though - you would have to provide all the user interface bits and just use the background "work out the actual phase" stuff.