O'Reilly logo

Sams Teach Yourself CGI in 24 Hours, Second Edition by Rafe Colburn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A C Example

This is a simple example of a form handling program written in C. It accepts user input submitted through a form, and prints the values that the user entered. The source code for the program appears in Listing 11.2.

Listing 11.2. A Sample CGI Program Written in C
 1: #include <stdio.h> 2: #include "cgic.h" 3: 4: void print_name(); 5: void print_secure(); 6: void print_operating_system(); 7: void print_browser(); 8: 9: int cgiMain() { 10: cgiHeaderContentType("text/html"); 11: fprintf(cgiOut, "<html><head>\n"); 12: fprintf(cgiOut, "<title>C Example</title></head>\n"); 13: fprintf(cgiOut, "<body><h1>C Example</h1>\n"); 14: print_name(); 15: print_secure(); 16: print_operating_system(); 17: print_browser(); 18: fprintf(cgiOut, "</body></html>\n"); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required