LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

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


hi,
I am looking for a good document to download on cgi with C/C++ with some script examples
thanks a lot
bela
 
Old 09-07-2003, 11:45 AM   #2
eric.r.turner
Member
 
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.

Code:
#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" );

   printf("</html>\n");

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

Code:
gcc -o foo.cgi foo.c
chmod 755 foo.cgi
Then access it from the web browser (e.g. http://www.bitbreather.com/~eric.r.turner/foo.cgi ).

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:

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

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


Reply


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 CGI.pm 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
http://www.burstnet.com/cgi-bin/ads/ad7954a.cgi/3980/RETURN-CODE rverlander LQ Suggestions & Feedback 1 06-07-2002 08:35 AM


All times are GMT -5. The time now is 06:45 PM.

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