html - C/HTML - 从 HTML 表单打印用户名和密码

标签 html c cgi

我们被要求使用 HTML、C/CGI 和 CSS 创建登录页面。我想从基础知识开始,首先是 HTML 和 C/CGI,所以我创建了这个:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
char *data;
char *user;
char *password;
printf("Content-type:text/html\r\n\r\n");
printf("<!DOCTYPE html><html><head><title>Welcome!</title></head><body>");
data = getenv("QUERY_STRING");
   if (data) {
       sscanf(data,"user=%s&password=%s", &user, &password);
       printf("Hello Mr./Ms. %s\n",user);
       printf("You entered your password %s\n",password);
      }
printf("<form action='http://localhost/inch.html'>");
printf("<input type=submit value='Compute'>");
printf("</body></html>");
exit(EXIT_SUCCESS);
}

但是,编译器向我展示了这个问题:

warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘char **’ [-Wformat=] sscanf(data,"user=%s&password=%s", &user, &password);

此外,HTML 显示错误 500。

关于如何解决这个问题有什么想法吗?我在 HTML/CGI 方面还很陌生,我很感激一路上的帮助。谢谢!

最佳答案

问题是,sscanf需要一个指向 char 的指针:

int sscanf ( const char * s, const char * format, ...);

试试这个:

char user[100];
char password[100];
// ...
sscanf(data,"user=%s&password=%s", user, password);

关于html - C/HTML - 从 HTML 表单打印用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40242667/

相关文章:

html - 表格边框顶部或底部未对齐

html - 是否可以更改加载到框架中的网站的 CSS 样式?

jquery - 我想让一个 div 在 Bootstrap 中滚动到顶部

php - 错误 500 : Premature end of script headers

javascript - 使用 AJAX 从 javascript 调用 Perl 脚本

html - HTML 中的位置图像图标无法按预期工作

c++ - GCC 或 Clang "moving target"是否有任何 `-std=` 别名值,暗示 "use the latest standard"?

c - 在图中使用队列进行拓扑排序

c - 指定长命令行参数而不使用短格式 getopt

c - 信号 CGI 输出在程序退出前完成