C curl / curl.h错误

时间:2013-06-29 23:51:31

标签: c cgi

我正在尝试使用curl / curl.h来清理URL输入,但是当我编译时,我得到以下错误:“错误:预期声明说明符或'x'之前的'...'。

它与代码行绑定:“char * curl_easy_escape(CURL * curl,char * Buffer,x);”但我不确定问题是什么。

#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <openssl/md5.h>
#include <curl/curl.h>

main(int argc, char **argv, char **envp) {

printf("Content-type: text/html\n\n");

char *qPtr;
FILE *fPtr;
unsigned char digest[MD5_DIGEST_LENGTH];
int i;
char mdString[33];
int x = 0;

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

//clean up URL
char *curl_easy_escape( CURL * curl, char *Buffer, x);


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

//Execute MD5 library on password string
MD5((unsigned char *)&password, strlen(password), (unsigned char*)&digest);

for(i = 0; i < 16; i++) {
     sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);
 } //end MD5


 Token = strtok(NULL, "&"); //get third query
 sscanf(Token, "email=%s", email); //gets value of email field input

 //write username, password and email to file
 fPtr = fopen("users.txt", "a+");
 fprintf(fPtr, "%s=",  username);
 fprintf(fPtr, "%s=", mdString);
 fprintf(fPtr, "%s\n", email);
 fclose(fPtr); 

} else { printf("<p>Error: did not get a QUERY_STRING variable."); }

}

2 个答案:

答案 0 :(得分:0)

从内部函数中删除此函数原型。这是无效的C代码。

char *curl_easy_escape( CURL * curl, char *Buffer, x);

顺便说一下,你的主要功能应该返回int

答案 1 :(得分:0)

尝试更改:

char *curl_easy_escape(CURL *curl, char *Buffer, x);

使用:

CURL *curl = curl_easy_init();
char *escapedBuffer = curl_easy_escape(curl, Buffer, x);

正如The Mask所说,你的主要功能应该返回int

你应该读到这个:

http://curl.haxx.se/libcurl/c/curl_easy_escape.html