因为使用Socket的程序在使用Socket之前必须调用WSAStartup函数。
你没有调用WSAStartup函数,所以返回NULL,
更多资料请看
http://www.vcgood.com/forum_posts.asp?TID=1885&PN=1&TPN=1
代码如下:
#include “winsock.h”
#include “stdio.h”
#pragma comment(lib,”wsock32.lib”)
int main(int argc, char *argv[])
{
struct hostent *host;
//加入这段话
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1, 1 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
return 1;
}
//结束
if((host=gethostbyname(“http://www.hao123.com“))==NULL)/*取得主机IP地址*/
{
fprintf(stderr,”Gethostname error, %s\n”, strerror(errno));
exit(1);
}
//还有以下这段话,一定要加
WSACleanup( );
return(1);
}
群没人回答问题不是因为你菜,也不是大家不肯帮忙.而是也许大家都很忙,有什么问题可以发到BBS,会有更多人帮你的..