WINDOWS系统:
//---------------------------------------------------------------------------
#include
#include
#define INFO_BUFFER_SIZE 32767
void main( )
{
TCHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
if( GetComputerName( infoBuf, &bufCharCount ) )
printf( "\nComputer name: %s", infoBuf );
}
//---------------------------------------------------------------------------
LINUX系统:
//---------------------------------------------------------------------------
#include
int main(void)
{
char str[256];
FILE *fp=fopen("/etc/hostname","r");
fgets(str, 256, fp);
puts(str);
return 0;
}
//---------------------------------------------------------------------------