当我简单地打印查询时,我得到:
一=1&二=2&三=3&四=3&五=3&六=3
还是不行!!!我快要疯了。
#include <stdio.h>
#include <stdlib.h>
int main(void){
char *data;
float prices[] = {1, 2, 3, 4, 5, 6};
int a, b, c, d, e, f;
printf("%s%c%c\n",
"Content-Type:text/html;charset=iso-8859-1",13,10);
printf("<title>Bill</title>\n");
printf("<h3 align=center >Bill</h3>\n");
data = getenv("QUERY_STRING");
if(data == NULL){
printf("<p>Error!</p>");
} else {
printf("%s", data);
sscanf(data, "one=%d&two=%d&three=%d&four=%d&five=%d&six=%d", &a, &b, &c, &d, &e, &f);
}
return 0;
}
最佳答案
Is there an easy and not error prone way to deal with this issue?
是的;存在各种C库,例如cgic和 C CGI ,处理像这样的常见 CGI 任务。 (如果这些都不符合您的口味,请尝试 Googling "C CGI library" 其他选项。)
关于html - 解析 HTML 表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9899440/