We did this in uni last year, it's quite easy when you know the little details.
Everything you want to appear on the web page you just printf.
You have to print the following line first though.
Content-Type:text/html\n\n
To do forms I think the best way is to use POST not GET. To set up the form just do what the above post says. Then the uri information is given on stdin. You can do something like this to read it all.
Code:
#define URI_MAX_LEN 1000
char uri[URI_MAX_LEN];
fgets(uri, URI_MAX_LEN, stdin);
The uri format is name=value?name2=value2?name3=value3 etc...
Just one thing I should point out.
Quote:
* Once you collect this data, CGI encode it and display the encoded string.
|
You don't "CGI encode it" as such. You printf everything, including the form you want data submitted (or the form can be a separate page which has its action as your CGI program), then you process the form.
However since this is a command prompt thing, not actually running on a web server, to CGI encode it you would just print it out as name=value?name2=value2 etc. sprintf is useful, just remember to check buffer lengths.
A tip: the "hidden" input element in html is very useful for saving some "state" in your program (HTML is completely stateless).
It seems like they're asking you to do something a little strange since CGI encoding is done by your internet browser, you can probably ignore half of what I said since it relates to actually making a CGI script to run on a web site.