我使用gcc编译我的编程,但在
中看到错误void sendemail(char *stmpServer, char *serveruser, char *serverpassword);
在test.c中包含的文件中:11:sendmail.c:46:错误:预期';', ','或')'在字符串常量sendmail.c之前:120:错误:预期';', 字符串常量之前的','或')'
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#include <netdb.h>
#define stmpServer "smtp.exmail.qq.com"
#define login_name "secbot@test.com"
#define login_passwd "123456"
#define mail_to "root@test.com"
#define ip "127.0.0.1"
int base64_encode(unsigned char *buf, int nLen, char *pOutBuf, int nBufSize);
void sendemail(char *stmpServer, char *serveruser, char *serverpassword);
但是我修改了这个
const char * stmpServer = "smtp.exmail.qq.com";
const char * login_name = "secbot@test.com";
const char * login_passwd = "123456";
const char * mail_to = "root@test.com";
const char * ip = "127.0.0.1";
......
void sendemail(char *stmpServer, char *serveruser, char *serverpassword);
void sendemail(char *stmpServer, char *serveruser, char *serverpassword)
{
int sockfd = 0;
struct sockaddr_in their_addr = {0};
char buf[1500] = {0};
char rbuf[1500] = {0};
char login[128] = {0};
char pass[128] = {0};
struct hostent *host = NULL;
if((host = gethostbyname(smtpServer))==NULL)
{
fprintf(stderr,"Gethostname error, %s\n", strerror(errno));
exit(1);
}
中的
if((host = gethostbyname(smtpServer))== NULL)
说
sendmail.c:130:错误:'smtpServer'未声明(首先在此使用 功能)
答案 0 :(得分:2)
您的代码正在评估
void sendemail(char *"smtp.exmail.qq.com", char *serveruser, char *serverpassword);
这不是合法的C代码。您的解决方案是更改参数名称
void sendemail(char *someOtherName, char *serveruser, char *serverpassword);
或更改定义名称,即
#define STMP_SERVER "smtp.exmail.qq.com"
答案 1 :(得分:1)
stmpServer
是#define
,用于您的签名。在签名中,它会扩展为字符串"smtp.exmail.qq.com"
答案 2 :(得分:0)
您的代码中存在拼写错误: 您声明了 tmp 服务器并将s mtp 服务器用于gethostbyname()。