LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 12:18 PM   #1
abd_bela
Member
 
Registered: Dec 2002
Location: algeria
Distribution: redhat 7.3, debian lenny
Posts: 627

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, 10:45 AM   #2
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint
Posts: 216

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 11:18 AM.
 
  


Reply



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 06:22 AM
trouble finding policy doc as pdf in doc mirrors stardotstar Debian 2 05-12-2005 10:56 PM
Script to check Doc-BBB against Doc-AAA for inconsistence satimis Programming 2 11-09-2004 01:43 AM
CGI to work out side of cgi-bin? crashedspine Linux - Newbie 13 09-02-2004 08:49 PM
http://www.burstnet.com/cgi-bin/ads/ad7954a.cgi/3980/RETURN-CODE rverlander LQ Suggestions & Feedback 1 06-07-2002 07:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:29 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration