我对 C 非常陌生,我正在尝试将从 main 之后的 decode 函数返回的数组分配给一个指针,以便我可以在我的程序中使用它(例如打印它)。代码可以编译,但是当我运行 CGI 时出现“错误 500”。
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
int main(int argc, char **argv, char **envp) {
printf("Content-type: text/html\n\n");
char *decode(char *url);
char *qPtr;
char *ePtr;
char *emailClean;
if(qPtr = getenv("QUERY_STRING")) {
char Buffer[256];
char *Token;
char username[80], password[80], email[80];
strncpy(Buffer, qPtr, 255); //copy Env variable "QUERY_STRING" into qPtr pointer
Token = strtok(Buffer, "&"); //get first query
sscanf(Token, "username=%s", username); //gets value of username field input
Token = strtok(NULL, "&"); //get second query
sscanf(Token, "password=%s", password); //gets value of password field input
Token = strtok(NULL, "&"); //get third query
sscanf(Token, "email=%s", email); //gets value of email field input
ePtr = email;
//decode email
emailClean = decode(ePtr);
printf("%s\n", *emailClean);
}
else { printf("<p>Error: did not get a QUERY_STRING variable."); }
}
char *decode(char *url) {
char *emailNew;
int i = 0;
int y = 0;
char current = url[i];
while(current != '%') {
emailNew[i] = current;
y++;
current = url[i++];
}
return emailNew;
}
谢谢!