gethostname 环境 -》错

#include "stdafx.h"
#include<winsock2.h>
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")
char m_sznode[32+1] = {0};
int GetComputerName(char *lpBuffer, unsigned long* lpnSize)
{
    if (gethostname(lpBuffer, *lpnSize) != -1)
    {
        *lpnSize = strlen(lpBuffer);
    }
    return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
    unsigned long ncomputerlong = sizeof(m_sznode)-1;
    GetComputerName(m_sznode,&ncomputerlong);
    printf("%s",m_sznode);
    system("PAUSE");
    return 0;
}

 

posted on 2020-05-21 20:38  lydstory  阅读(208)  评论(0)    收藏  举报

导航