What you want is CGIC: http://www.boutell.com/cgic/
You can also Google for: cgi c example
Important: HTTP headers should end with \r\n, not \n (this is done very often). So, instead of writing code like:
you should use:
And to end a HTTP header, you must use \r\n\r\n and NOT \n\n. If you have no idea what I'm talking about, don't worry. Just visit the CGIC website and start reading. Very soon you'll understand what I mean.