Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing a c/c++ CGI script/program?

Status
Not open for further replies.

qednick

Programmer
Jul 26, 2002
516
US
Hi again all,

Well I successfully managed to compile and run my very first 'hello world' c program on my UNIX web server by giving it a .cgi extension and pointing my browser at it.
I was so happy I decided to use C for my small cgi programs I write from now on (I know C a little better than Perl at the moment).

Now I have a couple of questions:

1. How do I retrieve the information being passed into my C/C++ cgi program via a web browser? Does anyone have any sample code for parsing the form via POST/GET methods?

2. I understand that it is possible to incoporate snippets of Perl code into a C/C++ program. But how do I do this?

3. Finally, could I expect my C/C++ cgi programs to run faster than the Perl script equivalents (because they are already compiled)???

Many thanks in advance...

Nick
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
1) Get onto the net and get the uncgi program. Then, in your forms, call your program through uncgi (ie /cgi_path/uncgi/yourapp. Any variables in your form are then passed by uncgi as environment variables to your program with the variable name prefixed by
A code snippet follows : The form has a variable called branch_name ---->

if((ptr=getenv(" *)NULL)
strcpy(sz_in_branch,ptr);


2) I'm not sure about this, I would think the only way to do this would be to call the system() call calling a perl script. The script would then run asyncronously to the calling C program so if one depended on the output of the other you have a bear of a syncronising problem.

3) YES

Cheers - Gavin
 
Thanks Gavin, I've actually written my own form parsing code in the meantime. I was being lazy and figured someone may already have some code to share :)

I have posted another question in a new thread though which is quite elemantary and you may be able to help me with.

BTW: thanks for the answers!

[rockband]
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Question #2... a system() command would work, but you wouldn't have t ocall the a script file, Perl does allow you to run lines of perl... loke typeing the perl onto the commandline....

This is useful when you want a qucik answer to a complicated math problem but don't have a calcultor or want to compile a program for such a trival one time thing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top