當前位置:編程學習大全網 - 編程軟體 - 如何用c語言編程查看本機主機名

如何用c語言編程查看本機主機名

WINDOWS系統:

//---------------------------------------------------------------------------

#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;

}

//---------------------------------------------------------------------------

  • 上一篇:動漫遊戲專業學什麽?
  • 下一篇:有沒有人能幫我講解壹下這個C語言程序的執行過程?
  • copyright 2024編程學習大全網