#include <stdio.h>
#include <stdlib.h>
#define BUF_SIZE 128
int name_pc(char* buf) {
FILE *p = popen("hostname", "r");
if (p == NULL)
return 0;
int r = 1;
if (!fgets(buf, BUF_SIZE, p))
r = 0;
pclose(p);
return r;
}
int main(int argc, char* argv[]) {
char hostname[BUF_SIZE];
if (!name_pc(hostname)) {
fputs("Error!", stderr);
return EXIT_FAILURE;
}
printf("%s\n", hostname);
return EXIT_SUCCESS;
}