To save you some future debugging / headaches.
1) you have to have proper http headers *before* the data is output and they contain the number of characters in the output. Therefore, you need to "buffer up" all your output inside the application before finally dumping it to 'stdout'
2) C/C++ Newline ('\n') will only count as 1 character in a buffer but will become two characters when you print it on 'stdout' so count the number of newlines separately and add that to the length of the buffered output.
Below is the bottom of my CGI app. I buffer the output into
and count newlines in
. How you do your output buffering and the like is up to you.
if (total_printout != NULL)
printf("Content-length: %d\n\n", strlen(total_printout)+total_newlines);