Html表单复选框未定义的行为

Html表单复选框未定义的行为,html,c,cgi,Html,C,Cgi,我有下面的html代码: <html> <head><title>OPTIONS</title></head> <body> <p>Choose schedule to generate:</p> <form action='cgi-bin/mp1b.cgi'> <input type=checkbox name='tfield' value=on />

我有下面的html代码:

<html>
<head><title>OPTIONS</title></head>
<body>
    <p>Choose schedule to generate:</p>
    <form action='cgi-bin/mp1b.cgi'>
    <input type=checkbox name='tfield' value=on />Teacher<input type=text name=teacher value=""/><br>
    <input type=checkbox name='sfield' value=on />Subject<input type=text name=subject value=""/><br>
    <input type=checkbox name='rfield' value=on />Room<input type=text name=room value=""/><br>
    <input type=submit value="Generate Schedule"/>
    </form>
</body>
</html>

您必须发送到C CGI程序,否则我们无法帮助您。@Jori已经插入了代码。当您单击复选框时,您确定查询字符串数据的格式是这样的吗?我的意思是,如果数据以
“tfield=on&…”“
开头,它会失败,不是吗。我还想知道谁相信关于CGI的问题是离题的。字符串
“tfield=on&teacher=&sfield=on&subject=&rfield=on&room=“
无法匹配
sscanf
格式
“teacher=%[^&]&subject=%[^&]&room=%s”
在第二个字符处(预期为
'e'
,获得
'f'
sscanf
在那里停止并返回0,您没有检查返回值(顽皮!),因此您不知道它失败了。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void)
{
    char *data;
    printf("Content-type:text/html\n\n");
    printf("<html><body>");
    data = getenv("QUERY_STRING");
    char teacher[1024] = "";
    char subject[1024] = "";
    char room[1024] = "";
    sscanf(data,"teacher=%[^&]&subject=%[^&]&room=%s",teacher,subject,room);    
    puts(teacher);
    puts(subject);
    puts(room);
    printf("</body></html>");
    return 0;
}