473,509 Members | 10,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CGI C and HTML

Merry Christmas to You all.
My system: WIN XP, DEV CPP 4.x(C compiler).

Consider this HTML code.

<HTML>
<BODY>

<FORM NAME="MyForm" ACTION="c:\PATH\MyProgram.exe" METHOD="GET"
ENCTYPE="application/x-www-form-urlencoded">

<INPUT TYPE="TEXT" NAME="MyString">
<INPUT TYPE="SUBMIT" NAME="Iaccept" VALUE="OK">
</FORM>
</BODY>
</HTML>
This code should have to produce a string("MyForm") and on SUBMIT,
this should be sent to MyProgram.exe to be processed.

Consider this C code.

#include <stdio.h>

void main(int argc, char *argv[]){

/* Your code */
char *MyForm;
FILE *filePtr;
filePtr=fopen("c:\\PATH\\MyText.txt","w");
fprintf(filePtr,"%s",MyForm);
return NULL;

}

The above C code should have to capture the HTML contents and to put
it into MyText.txt.
Does't interest to tokenize and to unescape the string.
I need to understand the mechanism of CGI C(pure ANSI C, better
unstructured).
Particularly, how could I capture by a C program a string comes from
another program.
For example, on command line by argv[], I can pass a string to the
program; unfortunately this procedure doesn't run between two
programs. Better I'm not able to exchange a string between programs,
without using any disk, only from RAM.

Greetings from Italy

Sergio
Nov 14 '05 #1
4 3200
Sergio wrote:
Consider this C code.

#include <stdio.h>

void main(int argc, char *argv[]){ ^^^^
This is not C code/

/* Your code */
char *MyForm;
FILE *filePtr;
filePtr=fopen("c:\\PATH\\MyText.txt","w");
Not checking the return from fopen() is poor form.
fprintf(filePtr,"%s",MyForm);
Trying to use the wild pointer MyForm is insane.
return NULL;
Returning a pointer is just stupid.
}

The above C code should have to capture the HTML contents and to put
it into MyText.txt.


No, it should eat shit and die.


--
Martin Ambuhl

Nov 14 '05 #2
Sergio wrote:
I need to understand the mechanism of CGI C(pure ANSI C, better
unstructured).


It's quite easy to do CGI in standard C. I suggest that you get hold of a
good book on CGI.

Hints: you will need to use getenv to find out the value of the
"REQUEST_METHOD" environment variable. If it's "GET", then you'll need to
call getenv again to find out the value of the "QUERY_STRING" environment
variable (which contains your data). Otherwise, if it's "POST", you'll need
to use getenv() to query the value of the "CONTENT_LENGTH" environment
variable, which tells you how much data you can expect to find on stdin.

Easy, huh?

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #3

"Sergio" <em*****@libero.it> wrote in message
news:6d**************************@posting.google.c om...
Merry Christmas to You all.
My system: WIN XP, DEV CPP 4.x(C compiler).

Consider this HTML code.

<HTML>
<BODY>

<FORM NAME="MyForm" ACTION="c:\PATH\MyProgram.exe" METHOD="GET"
ENCTYPE="application/x-www-form-urlencoded">

<INPUT TYPE="TEXT" NAME="MyString">
<INPUT TYPE="SUBMIT" NAME="Iaccept" VALUE="OK">
</FORM>
</BODY>
</HTML>
This code should have to produce a string("MyForm") and on SUBMIT,
this should be sent to MyProgram.exe to be processed.

Consider this C code.

#include <stdio.h>

void main(int argc, char *argv[]){

/* Your code */
char *MyForm;
FILE *filePtr;
filePtr=fopen("c:\\PATH\\MyText.txt","w");
fprintf(filePtr,"%s",MyForm);
return NULL;

}

The above C code should have to capture the HTML contents and to put
it into MyText.txt.
Does't interest to tokenize and to unescape the string.
I need to understand the mechanism of CGI C(pure ANSI C, better
unstructured).
Particularly, how could I capture by a C program a string comes from
another program.
For example, on command line by argv[], I can pass a string to the
program; unfortunately this procedure doesn't run between two
programs. Better I'm not able to exchange a string between programs,
without using any disk, only from RAM.

Greetings from Italy

Sergio


To pass data between two programs you can read and write to stdin and
stdout. So if you have
prog1, prog2 and prog3 that all read from stdin and write to stdout then on
the command line you can
do something like:

prog1 | prog2 | prog3

Sean

Nov 14 '05 #4
em*****@libero.it (Sergio) writes:
Merry Christmas to You all.
My system: WIN XP, DEV CPP 4.x(C compiler).

Consider this HTML code.
[...]

Sorry, no, I don't think I will.
Consider this C code.

#include <stdio.h>

void main(int argc, char *argv[]){

/* Your code */
char *MyForm;
FILE *filePtr;
filePtr=fopen("c:\\PATH\\MyText.txt","w");
fprintf(filePtr,"%s",MyForm);
return NULL;

}


Ok.

I doubt that the above code would compile (since you try to return a
value from a void function). If you're going to post C code here,
please make sure it compiles and cut-and-paste it exactly; don't try
to paraphrase, or we'll get stuck on any errors you introduce by
paraphrasing it.

main() returns int, not void.

You fail to check the result of fopen(). What happens if it fails?

MyForm is never initialized, so you're passing garbage to fprintf().

Returning NULL from main makes no sense. The values you can portably
return from main() (assuming you declare it properly to return int)
are 0, EXIT_SUCCESS (both indicating success) and EXIT_FAILURE
(indicating failure). EXIT_SUCCESS and EXIT_FAILURE are macros
defined in <stdlib.h>. (Other values can be used, but not in portable
code; for example, the commonly used "exit(1);" indicates failure on
Unix, but success on VMS.) The NULL macro expands to a null pointer
constant; in some cases, the compiler may fail to warn you if you use
"return NULL;" in main(), but it's still incorrect.

Any questions about CGI and HTML belong in another newsgroup. If you
have questions about C, such as how to read from standard input or how
to obtain the values of environment variables, they're appropriate
here, but first consult your C textbook, your online documentation,
and the C FAQ at <http://www.eskimo.com/~scs/C-faq/top.html>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8386
by: VK | last post by:
09/30/03 Phil Powell posted his "Radio buttons do not appear checked" question. This question led to a long discussion about the naming rules applying to variables, objects, methods and properties...
4
2954
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text...
1
2397
by: cirillo_curiosone | last post by:
Hi, i'm new to javascript. I started studing it on the web few weeks ago, but still haven't been able to solve one big problem: HOT TO PASS VALUES FROM A SCRIPT VARIABLE TO A CHILD HTML...
33
4728
by: LRW | last post by:
http://gto.ie-studios.net/index.php When you view the above site in IE, if the 1st of the three product images is tall enough to push the cell down a couple of pixels, IE somehow doesn't show...
0
395
by: Boris Ammerlaan | last post by:
This notice is posted about every week. I'll endeavor to use the same subject line so that those of you who have seen it can kill-file the subject; additionally, Supersedes: headers are used to...
9
1985
by: Patient Guy | last post by:
Taking the BODY element as an example, all of its style attributes ('alink', 'vlink', 'background', 'text', etc.) are deprecated in HTML 4.01, a fact noted in the DOM Level 2 HTML specification. ...
5
3565
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
6
433
by: Guy Macon | last post by:
cwdjrxyz wrote: HTML 5 has solved the above probem. See the following web page: HTML 5, one vocabulary, two serializations http://www.w3.org/QA/2008/01/html5-is-html-and-xml.html
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.