Does anyone know where I can learn to do CGI in C\C++? I''ve done a few searches but can''t seem to find much. I would rather not have to learn Perl.
"YOU APES WANNA LIVE FOREVER?" Starship Troopers by Robert A. Heinlein
"Who wants to live forever?" Queen
"Never trust a bald barber" me
B^)
It''s very simple. Input to your CGI will come in either the standard input or environment variables. Use cin or scanf() to read from standard input and you can use either getenv() to read specific environment variables or the environ variable to get access to the full set of environment variables. (Assuming you''re on a UNIX host (not a bad assumption for CGI), see your compiler documentation for access environment variables otherwise). The HTML output is read from standard out. Use either cout or printf to write to standard out.
The simplest C CGI:
The simplest C CGI:
int main(int argc, char ** argv) { printf("<html&ht<body>Hello world<br></body></html>\n"); return 0;}
May 29, 2000 07:17 AM
Nope, that example won''t work, or at least it shouldn''t. Otherwise what siCrane said is true, but before you can print any output to the browser, you have to send the content type like this:
#include
int main(void)
{
printf("Content-type: text/html\n\n");
printf("Hello World</body></html>\n");
return 0;
}
#include
int main(void)
{
printf("Content-type: text/html\n\n");
printf("Hello World</body></html>\n");
return 0;
}
Oops.. That anonymous poster was me.. Sorry, the code I posted got messed up, this is how it should be:
#include <stdio.h;>
int main(void)
{
printf("Content-type: text/html\n\n");
printf("<html><body>Hello World</body></html>
return 0;
}
#include <stdio.h;>
int main(void)
{
printf("Content-type: text/html\n\n");
printf("<html><body>Hello World</body></html>
return 0;
}
Could someone point me to some host that supports CGI scripts written in C++? After an hour trying to set up a simple "Hello World" CGI script written in C++ on Hypermart, I noticed that this was in the FAQ:
You cannot run CGI scripts written in C++, Visual Basic or some other language.
Argh!!!
Anyway, should CGI scripts written in C++ be uploaded in ASCII mode or BINARY mode? Should I upload the .exe that I get from the compilation, the object file or perhaps something completely else? Can I use DJGPP or VC to compile the scripts?
Does anyone know a good site where I can get answers to all my stupid questions?
/. Muzzafarath - Feeling VERY frustrated right now
Edited by - Muzzafarath on May 29, 2000 3:00:20 PM
You cannot run CGI scripts written in C++, Visual Basic or some other language.
Argh!!!
Anyway, should CGI scripts written in C++ be uploaded in ASCII mode or BINARY mode? Should I upload the .exe that I get from the compilation, the object file or perhaps something completely else? Can I use DJGPP or VC to compile the scripts?
Does anyone know a good site where I can get answers to all my stupid questions?

/. Muzzafarath - Feeling VERY frustrated right now

Edited by - Muzzafarath on May 29, 2000 3:00:20 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Why not just learn Perl? I got a whole book on it, thinking it would be kinda difficult, but it''s not. You can really learn it just from some online tutorials. Besides using the funny characters like ''$'' in front of variables, it''s very similar to C++ (in fact, many parts of it are based on C/C++). Besides, there are a lot of cool built-in functions for strings, which is mainly what you use Perl (and CGI) for. So my advice: JUST LEARN PERL.
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
I COULD learn Perl, but why? I just want to test this CGI thingy
Perl is probably not that hard to learn when you know C/C++ pretty good, but it would require me to buy a book on the subject, which costs money, which I have very little of right now
But just now, I just want to test C++ and CGI 
Perl probably has its uses though. For example, I''ve heard there''s a "close to" operator (~= maybe?) which may come in handy
/. Muzzafarath



Perl probably has its uses though. For example, I''ve heard there''s a "close to" operator (~= maybe?) which may come in handy

/. Muzzafarath
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
I''ve done much C CGI programming some time ago. Information on this topic is VERY hard to find. But I can give you a bit of (hopefully good) advice:
- The only time I found usefull information on this on the internet was with a query like: "Content-Type: text/html".
- Be aware! Microsoft exploiter and Nepscape navigator work different with CGI!!!!!!! BIG PROBLEMS HERE! Some time ago I wanted people to download my data via a CGI program (Send back: Content-Type: binary? orso), so you could register when someone downloaded info in your own database. It was a real problem to get the filename through to the other end. Netscape handled it just fine, but the explorer made up it''s own filenames (Like 21765376.$$$ orso). Never corrected this problem until now!
Wish you lot''s of luck, hoping you have a hard head!
Bas.
- The only time I found usefull information on this on the internet was with a query like: "Content-Type: text/html".
- Be aware! Microsoft exploiter and Nepscape navigator work different with CGI!!!!!!! BIG PROBLEMS HERE! Some time ago I wanted people to download my data via a CGI program (Send back: Content-Type: binary? orso), so you could register when someone downloaded info in your own database. It was a real problem to get the filename through to the other end. Netscape handled it just fine, but the explorer made up it''s own filenames (Like 21765376.$$$ orso). Never corrected this problem until now!
Wish you lot''s of luck, hoping you have a hard head!
Bas.

CGI with C/C++ is pretty easy. Since you''re starting out you''re probably only concerned with knowing enough to get you started. So on that note, check out CGI-Resources. It has a ton of stuff you should find useful..
---
Michael Tanczos
---
Michael Tanczos
If you finally break down and learn Perl. Just go to www.informit.com and www.itknowledge.com. Informit has around 5 books and itknowledge has even more on perl.
I wish there was a button on my monitor to turn up the intellegince. Theres a button called 'brightness' but it doesn't work
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement