PDA

View Full Version : CGI String Format



sean
03-12-2002, 05:36 PM
a) Is the string passed to the ci file from a web site null terminated, or does it just END.

b) how do you get it into the file? Is it like this:

char anyname[CONTENT_LENGTH];
scanf(anyname);

If not, HOW!?

Thanksin advance if you can help.

Prelude
03-12-2002, 07:11 PM
>Is the string passed to the ci file from a web site null terminated, or does it just END.
String input works the same with CGI as with anything else, both with stdin and arguments to main.

>how do you get it into the file?
The easiest way is to read a string and then parse it. fgets is ideal for this. You can also use argc and argv:


#include <stdio.h>
#include <stdlib.h>
#define OPEN "<HTML><BODY>"
#define CLOSE "</BODY></HTML>"

int main ( int argc, char **argv )
{
char msg[BUFSIZ];
if ( argc > 1 )
parseMsg ( msg, argv[1] );
printf ( "Content-type: text/html\n\n" );
printf ( "%s\n%s\n%s\n", OPEN, msg, CLOSE );
return EXIT_SUCCESS;
}

-Prelude