Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writing cgi code by C language

Tags:

c++

c

cgi

Is this possible to write CGI code by C or C++ ? please give me a "hello World !!!" Example .

like image 931
Amra Avatar asked Nov 30 '22 09:11

Amra


2 Answers

Absolutely.

#include <stdio.h>

int main(int argc, char *argv[]])
{
  printf("Content-type: text/plain\n\n");
  printf("Hello, world!\n")
}
like image 189
Ignacio Vazquez-Abrams Avatar answered Dec 18 '22 08:12

Ignacio Vazquez-Abrams


Eva, once you understand the basics of Ignacio's answer (cgi-bin, executing from browser, web server, etc) there are some very helpful libraries to assist with web type execution.

Here is the library I used for my cgi in C, works great, saves you days:
(cgihtml is a set of CGI and HTML routines written for C)
http://eekim.com/software/cgihtml/index.html

you can add html templates for displaying large amounts of data:
http://www.algonet.se/~thunberg/template2doc/

Light weight WebServers:
http://en.wikipedia.org/wiki/Comparison_of_lightweight_web_servers

and more resources:
http://cgi.resourceindex.com/Programs_and_Scripts/C_and_C++/Libraries_and_Classes/

http://en.wikipedia.org/wiki/Common_Gateway_Interface

like image 43
T.T.T. Avatar answered Dec 18 '22 09:12

T.T.T.