#include <stdio.h> int main(void){ char cpnm[MAX_COMPUTERNAME_LENGTH+1]; DWORD len; len=MAX_COMPUTERNAME_LENGTH+1; GetComputerName(cpnm,&len); printf("this computer name is %s\n", cpnm); return 0; }
$ gcc -o main main.c
main.c: In function ‘main’:
main.c:4:12: error: ‘MAX_COMPUTERNAME_LENGTH’ undeclared (first use in this function)
char cpnm[MAX_COMPUTERNAME_LENGTH+1];
^~~~~~~~~~~~~~~~~~~~~~~
main.c:4:12: note: each undeclared identifier is reported only once for each function it appears in
main.c:5:2: error: unknown type name ‘DWORD’
DWORD len;
^~~~~
main.c:9:2: warning: implicit declaration of function ‘GetComputerName’ [-Wimplicit-function-declaration]
GetComputerName(cpnm,&len);
^~~~~~~~~~~~~~~
GetComputerNameではなく、gethostnameか。
#include <stdio.h> #include <unistd.h> // インプリメンテーション固有関数 int main(void){ char hostname[128]; gethostname(hostname, sizeof(hostname)); printf("host name is %s\n", hostname); return 0; }
$ ./main
host name is ubuntu-bionic
ほうー