473,586 Members | 2,678 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="applic ation/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\\MyTex t.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 3207
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\\MyTex t.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_STRI NG" 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.pow ernet.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.goo gle.com...
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="applic ation/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\\MyTex t.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\\MyTex t.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_Keit h) 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
8396
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 in JavaScript/JScript and HTML/XML elements. Without trying to get famous :-) but thinking it would be interesting to others I decided to post the...
4
2961
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 email by creating a text file, with content following certain format, and saving that file into the correct '..\mailroot\pickup' folder, and it is...
1
2406
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 GENERATED BY FUNCTION. Here'e the point: I'm writing a simple website for showing my photographs. It has a central page with many links (as many as...
33
4754
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 that happening. But if you look at it in Firefox you can see the small gap of white where the semi-circle image is broken. I've tried changing...
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 ensure that only one copy resides on a given news server. This notice was last updated on March 9th, 2005, and is available (with a complete...
9
1996
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. The DOM specification does not explicitly itself deprecate the use of attributes however for the element in the interface definition section I...
5
3579
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 that for server control component , code is running on the server side. But if I take as example a Label. I place on a webform an HTM label...
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
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.