//---------------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#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 <stdio.h>
int main(void)
{
char str[256];
FILE *fp=fopen("/etc/hostname","r");
fgets(str, 256, fp);
puts(str);
return 0;
}
//---------------------------------------------------------------------------