+ Reply to Thread
Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By franco67
  • 1 Post By misson

Thread: CGI Programming in C

  1. #1
    franco67 is offline x10Hosting Member franco67 is an unknown quantity at this point
    Join Date
    Aug 2010
    Posts
    5

    CGI Programming in C

    Hi would this c program compiled into cgi (using gcc) work on this site?

    #include <stdio.h>
    #include <stdlib.h>
    int main(void)
    {
    char *data;
    long m,n;
    printf("%s%c%c\n",
    "Content-Type:text/html;charset=iso-8859-1",13,10);
    printf("<TITLE>Multiplication results</TITLE>\n");
    printf("<H3>Multiplication results</H3>\n");
    data = getenv("QUERY_STRING");
    if(data == NULL)
    printf("<P>Error! Error in passing data from form to script.");
    else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2)
    printf("<P>Error! Invalid data. Data must be numeric.");
    else
    printf("<P>The product of %ld and %ld is %ld.",m,n,m*n);
    return 0;
    }
    dinomirt96 likes this.

  2. #2
    misson is online now x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: CGI Programming in C

    Please delimit code with [code], [html] or [php] tags (as appropriate) to separate it from the rest of the post and format it.

    This topic has been covered before on these very forums. Read over those now.

    "Will this work?" is a vague question; if the other threads don't answer your question, please restate it to make the question more specific.

    One difficulty you'll need to surmount is compiling the source for the specific Linux distro that X10 uses (CentOS 5.5).
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    worldwise001's Avatar
    worldwise001 is offline x10Hosting Member worldwise001 is an unknown quantity at this point
    Join Date
    Dec 2007
    Location
    Carbondale, IL
    Posts
    57

    Re: CGI Programming in C

    I forsee a number of issues here.

    a) As Misson said, you can't be certain of the version of gcc (minor issue) nor the version of libc (major issue).

    b) printf prints to stdout by default unless the wrapper somehow pipes that to network stream.

    c) that is a horrible program to be using http/cgi to wrap... it would be better to just write your own C network daemon.


  4. #4
    misson is online now x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: CGI Programming in C

    Quote Originally Posted by worldwise001 View Post
    b) printf prints to stdout by default unless the wrapper somehow pipes that to network stream.
    As per the CGI spec, the CGI process's stdout is returned to the HTTP client, possibly after processing by the web server.
    karimirt47 likes this.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Help, I don't know programming!!!
    By aircar in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 11-20-2009, 09:58 AM
  2. Need help in programming with vb6
    By lordskid in forum Computers & Technology
    Replies: 2
    Last Post: 05-15-2008, 03:31 AM
  3. New in the web programming
    By oregonsv in forum Introductions
    Replies: 3
    Last Post: 11-15-2007, 05:59 AM
  4. PHP Programming!!
    By darkuranium in forum The Marketplace
    Replies: 4
    Last Post: 11-25-2005, 04:31 PM

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
x10hosting free hosting for the masses
dedicated servers