📄 getinfo.c
字号:
/* Change this if the SERVER_NAME environment variable does not report
the true name of your web server. */
#if 1
#define SERVER_NAME cgiServerName
#endif
#if 0
#define SERVER_NAME "www.boutell.com"
#endif
/* You may need to change this, particularly under Windows;
it is a reasonable guess as to an acceptable place to
store a saved environment in order to test that feature.
If that feature is not important to you, you needn't
concern yourself with this. */
#ifdef WIN32
#define SAVED_ENVIRONMENT "c:\\cgicsave.env"
#else
#define SAVED_ENVIRONMENT "/tmp/cgicsave.env"
#endif /* WIN32 */
#include <stdio.h>
#include "cgic.h"
#include <string.h>
#include <stdlib.h>
struct _VISITOR{
char *name;
char *age;
char *sex;
}VISITOR;
void HandleSubmit();
char * get_name();
char * get_sex();
char * get_age();
struct VISITOR visitor;
int cgiMain() {
/* Send the content type, letting the browser know this is HTML */
cgiHeaderContentType("text/html");
/* Top of the page */
fprintf(cgiOut, "<HTML><HEAD>\n");
fprintf(cgiOut, "<TITLE>cgic test</TITLE></HEAD>\n");
fprintf(cgiOut, "<BODY><H1>cgic test</H1>\n");
/* If a submit button has already been clicked, act on the
submission of the form. */
if(cgiFormSubmitClicked("submit") == cgiFormSuccess)
{
HandleSubmit();
fprintf(cgiOut, "<hr>\n");
}
/* Now show the form */
ShowForm();
/* Finish up the page */
fprintf(cgiOut, "</BODY></HTML>\n");
return 0;
}
void HandleSubmit()
{
visitor->name = get_name();
visitor->age = get_age();
visitor->sex = get_sex();
}
char * get_name(){
char name[81];
cgiFormStringNoNewlines("name",name,81);
return name;
//fprintf(cgiOut,"Name:");
//cgiHtmlEscape(name);
//fprintf(cgiOut,"<BR>\n");
}
char * get_age(){
char age[81];
cgiFormStringNoNewlines("age",age,81);
return age;
//fprintf(cgiOut,"Name:");
//cgiHtmlEscape(name);
//fprintf(cgiOut,"<BR>\n");
}
char *sexs[] = {
"男",
"女",
};
char * get_sex() {
int sexChoice;
//char sexText[10];
cgiFormRadio("sex", sexs, 2, &sexChoice, 0);
return sexs[sexChoice];
//fprintf(cgiOut, "Age of Truck: %s (method #1)<BR>\n", ages[ageChoice]);
//cgiFormString("age", ageText, 10);
//fprintf(cgiOut, "Age of Truck: %s (method #2)<BR>\n", ageText);
}
void ShowForm()
{
fprintf(cgiOut, "<!-- 2.0: multipart/form-data is required for file uploads. -->");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -