CGI programming in C/alternatives
This is my first post. Hope to contribute constructively at some point :). I'm a university student, new to C and not quite capable of C++ yet. I was thinking of writing some simulation software in C as a practical exercise. I'd like to deploy it rather quickly, and perhaps in parts, so I was thinking of writing it up as a set of cgi scripts that would get called on a website, and use the browser's presentation capabilities to draw or at least present the output.
I'm considering the web deployment because it seems the quickest path to having a useable (and user-friendly) program, and I'm far from GUI programming in C. Furthermore, once my C programming skills improve to that level, I'm under the impression it won't take much to convert them to an executable.
I haven't been able to find many books or resources that cover C CGI programming. Is there a reason for this? Is my approach wrong? Will CGI in C be too slow compared with other server-side languages (PHP is the only one I'm seriously considering)?
Could anyone point me towards some CGI in C programming resources if this does seem like a viable option?
Thanks for your insight, and sorry for the long post,
Have a good one,
Not sure what CGI even is, but I often have my programs output programs as a file or whatever, for example the output of many of our programs is a matlab(tm) program, or a batch file, or even another C++ program(!), HTML, etc, or comma divided file that excel(tm) can read directly.
Perhaps that would work for you, to simply write a CGI script/program from the C output? Or HTML?
Edit: you cannot, to my knowedge, call an executable from a browser without funkyness, and certainly your security settings should prevent this. Instead, you would write the c program to generate the output script that the browser can handle and invoke the browser with the file at the end of the C program ... for example, system("C:\\.... IExplore.exe output.html"); would open internet explorer with the file output.html displayed, you can do the same with excel and word and just about any program (most will accept a command line file to open).
Originally Posted by jonnin
CGI in C: Outdated Server-Side Technology?
Hello again, I think I need to clarify.
I'm trying to decide in which direction I oughta guide my programming studies.
sorry for the long post again, the last three paragraphs highlight my question.
The fact that you can do this in C excites me because I'm under the impression that I could write the program as a series of CGI scripts and then, at a later date, simply put them together in a C executable when I'm ready to make a proper downloadable program. This would avoid having to learn a second programming language to make a server program, and still learn C well enough to make a proper executable.
My biggest hurdle is that while there are many resources (safariTechBooks) that cover CGI and Perl, there aren't many that cover CGI and C and I'm wondering if this is because C just isn't suited to run this way or if it's too slow to be practical etc.
Do you all think that it's a good idea to pursue writing CGI scripts in C for the sole benefit of being able to later put them together in a C executable?
Are other CGI or server-side languages better suited for this to where the convenience of porting to an executable is nullified?
Might this (writing a server-side app and .exe in same language) be a lost cause? Thanks again,
p.s. Java seems hard, and for numerical computations, reportedly ALOT slower:
However, other authors note that when benchmarks are written to be algorithmically comparable, overall C++ runs about twice as fast as Java
> Will CGI in C be too slow compared with other server-side languages...?
No. In terms of pure execution speed, C would be faster than Perl , Python or Java.
> once my C programming skills improve to that level, I'm under
> the impression it won't take much to convert them to an executable.
A C program used with CGI *is* an executable, getting input via environment variables and sending the output by writing to stdout eg. printf() see http://hoohoo.ncsa.illinois.edu/cgi/primer.html
> I haven't been able to find many books or resources that cover C CGI programming.
> Is there a reason for this?
yes, there is a good reason. The vast majority of CGI programs are written in languages, such as Perl, Python or Ruby - these languages are easier to use, and quite often a CGI script does not need the performance and low level control that C gives. and the structure of a CGI program is identical, no matter which language you use.
> Could anyone point me towards some CGI in C programming ...
here is a tutorial using C that would get you going immediately: http://www.cs.tut.fi/~jkorpela/forms/cgic.html
here is another: http://www.purplepixie.org/cgi/howto.php
The other thing is that executables are less portable. C is a moderately portable language (C++ a bit less, as folks tend to use more OS specific tools in it), but even the simple act of recompiling C code on another machine(different OS and hardware, not just a clone of the first machine of course) can lead to days of work. This would make the scripting languages, which are extremely portable, more acceptable for web-work. If you want to do it in C for the speed, or just to say you did it, or if you have no reason to port, its all good, but it may not be the best choice in general.
By Kallahan in forum Java
Last Post: 01-20-2003, 08:28 AM
By Novosoft in forum web.announcements
Last Post: 02-14-2001, 03:50 AM
By Bo Blodgett in forum Web
Last Post: 11-17-2000, 04:38 AM
By Philip King in forum authorevents.appleman
Last Post: 04-10-2000, 12:27 AM
Tags for this Thread
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center