CGI Programming in C

franco67

New Member
Messages
5
Reaction score
0
Points
0
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;
}
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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 [URL="http://catb.org/esr/faqs/smart-questions.html#before"]covered before[/URL] on [URL="http://lmgtfy.com/?q=site%3Ax10hosting.com+cgi+compile"]these very forums[/URL]. Read over those now.

"Will this work?" is a [URL="http://catb.org/esr/faqs/smart-questions.html#explicit"]vague question[/URL]; 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 [URL="http://www.landley.net/writing/docs/cross-compiling.html"]compiling[/URL] the source for the specific Linux distro that X10 uses (CentOS 5.5).
 

worldwise001

Member
Messages
57
Reaction score
1
Points
8
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.
 
Top