/* redirects the output of "ypcat hosts" to grep "" redirected to "host.dat"(temporary) file. Read the resulting line into Adrs, which is 16 characters long (note that the machine host name starts on the 17th character on each line. */ #include FILE *fin; int i; main(int argc, char *argv[]) { char Machine[31]; char Adrs[16], cmd[60]; gethostname(Machine,31); sprintf(cmd,"ypcat hosts | grep %s > host.dat ",Machine); system(cmd); fin = fopen("host.dat","r"); fscanf(fin,"%s\n",Adrs); fclose(fin); unlink("host.dat"); fprintf(stderr,"%s\n",Adrs); }