CGI programming in C/alternatives


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: CGI programming in C/alternatives

  1. #1
    Join Date
    Apr 2009
    Location
    Lafayette, IN
    Posts
    2

    Red face CGI programming in C/alternatives

    Hello,

    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,

    Alex

  2. #2
    Join Date
    Dec 2003
    Posts
    3,366
    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?

  3. #3
    Join Date
    Dec 2003
    Posts
    3,366
    Quote Originally Posted by jonnin View Post
    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).

  4. #4
    Join Date
    Apr 2009
    Location
    Lafayette, IN
    Posts
    2

    Red face 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.

    I ultimately want to make this a server-side application so that a webbrowser can be tasked with whatever post-processing is necessary. I'd like to take the trouble of writing a post-processing script (MATLAB, or using EXCEL) out of the user experience and have the output displayed nicely in a browser using it's visualization capabilities. ( I think I know JavaScript rather well compared to C).

    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,

    Alex

    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

  5. #5
    Join Date
    Dec 2007
    Posts
    401
    > 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

  6. #6
    Join Date
    Dec 2003
    Posts
    3,366
    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.

Similar Threads

  1. initial Java programming
    By Kallahan in forum Java
    Replies: 1
    Last Post: 01-20-2003, 09:28 AM
  2. Outsource your Java & C++ programming to Novosoft!
    By Novosoft in forum web.announcements
    Replies: 0
    Last Post: 02-14-2001, 04:50 AM
  3. Can CGI do interprocess communication?
    By Bo Blodgett in forum Web
    Replies: 2
    Last Post: 11-17-2000, 05:38 AM
  4. Replies: 1
    Last Post: 04-10-2000, 01:27 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center