All pastes #736358 Raw Edit

Unnamed

public c v1 · immutable
·published 2007-10-14 13:32 UTC
rendered paste body
#define BUFF 100int get_hosts(char *hosts[][BUFF]) {  FILE *stream;  char line[BUFF];  int i = 0,j;  if (!(stream = fopen(HOSTFILE,"r")))    return 0;  while ((fgets(line, BUFF, stream)))    strncpy(&hosts[i++], line, strlen(line)-1);  for (j=0;j<i;j++)    printf("host %d: %s\n",j,hosts[j]);  return i;}int main(int argc, char **argv){  int ntask, i;  char buf[BUFF], hosts[BUFF][BUFF];  if (!(ntask = get_hosts(&hosts))) {    printf("Could not get any hosts\n");    exit(EXIT_FAILURE);  }  for (i=0;i<ntask;i++)    printf("host %d: %s\n",i,hosts[i]);  return 0;}