Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-06-2003, 01:18 PM   #1
Registered: Dec 2002
Location: algeria
Distribution: redhat 7.3, debian lenny
Posts: 620

Rep: Reputation: 31
doc on CGI with c/c++

I am looking for a good document to download on cgi with C/C++ with some script examples
thanks a lot
Old 09-07-2003, 11:45 AM   #2
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint Debian Edition (LMDE)
Posts: 215

Rep: Reputation: 31
I'm not sure about any documents out there, but really all a CGI program has to do is print "Content-type: text/html\n\n" at the beginning, then anything you print to stdout will go to the client's web browser. Below is a simple C program that prints an ordered list of 0 through 9.

#include <stdio.h>

int main( int argc, char* argv[] )
   int i = 0;

   printf( "Content-type: text/html\n\n" );

   printf( "<html>\n" );

   printf( "<head>\n" );
   printf( "<title>\n" );
   printf( "This is a test of doing CGI from C.\n" );
   printf( "</title>\n" );
   printf( "</head>\n");

   printf( "<body>\n" );
   printf( "<p>Here's how you make an ordered list:\n" );
   printf( "<ol>\n" );
   for( i=0; i < 10; i++ ) {
      printf( "<li>%d\n", i );
   printf( "</ol>\n" );
   printf( "</body>\n" );


   return( 0 );
Compile it, and make sure it has correct executable permissions:

gcc -o foo.cgi foo.c
chmod 755 foo.cgi
Then access it from the web browser (e.g. ).

If I were doing this sort of thing for a real-world environment (and had to use C or C++) I'd probably use C++ and create classes that print themselves correctly. Something like:

OrderedList* numberRange = new OrderedNumberRange(0,9);
cout << *numberRange << endl;

Last edited by eric.r.turner; 09-07-2003 at 12:18 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl CGI:Can't locate supermyself Programming 13 09-10-2007 07:22 AM
trouble finding policy doc as pdf in doc mirrors stardotstar Debian 2 05-12-2005 11:56 PM
Script to check Doc-BBB against Doc-AAA for inconsistence satimis Programming 2 11-09-2004 02:43 AM
CGI to work out side of cgi-bin? crashedspine Linux - Newbie 13 09-02-2004 09:49 PM rverlander LQ Suggestions & Feedback 1 06-07-2002 08:35 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:25 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration