title: reading from a file descriptor in C
body: <p>(correct me if im wrong on my terms) So i need to read from a file descriptor, but the read method takes in a int for byte size to read that much OR i can use O_NONBLOCK, but i still have to setup up a buffer size of an unknown size. making it difficult. heres what i have so far</p>
  
  <p>this is my method that handles all the polling and mkfifo. and N is already predefined in main</p>
  
  <pre><code>struct pollfd pfd[N];
  int i;
  for(i = 0; i &lt; N; i++)
  {
      char fileName[32];
      snprintf (fileName, sizeof(fileName), "%d_%di", pid, i);
      mkfifo(fileName, 0666);
      pfd[i].fd = open(fileName, O_RDONLY | O_NDELAY);
      pfd[i].events = POLLIN;
      pfd[i].revents = 0;
  
      snprintf (fileName, sizeof(fileName), "%d_%do", pid, i);
      mkfifo(fileName, 0666);
      i++;
      pfd[i].fd = open(fileName, O_WRONLY | O_NDELAY);
      pfd[i].events = POLLOUT;
      pfd[i].revents = 0;
      i--;
  }
  while(1)
  {
      int len, n;
      n = poll(pfd, N, 2000);
      if( n &lt; 0 )
      {   
          printf("ERROR on poll");
          continue;
      }
      if(n == 0)
      {
          printf("waiting....\n");
          continue;
      }
      for(i = 0; i &lt; N; i++)
      {
          char buff[1024]; &lt;---i dont want to do this
  
          if (pfd[i].revents &amp; POLLIN)
          {
              printf("Processing input....\n");
              read(pfd[i].fd, buff, O_NONBLOCK);
              readBattlefield(buff);
              print_battleField_stats();
              pfd[i].fd = 0;
          }
      }
  }
  </code></pre>
  
  <p>i also read somewhere that once read() reads all the data coming, it empties the pipe, meaning i can use the same again for another incoming data. but it doesnt empty the pipe because i cant use the same pipe again. I asked my professor but all he says was to use something like scanf, but how do use scanf if scanf takes a FILE stream, and the poll.fd is an int? essentially my ultimate question is, how to read the incoming data through the file descriptor using scan or of other sort? using scan will help me more with handling the data.</p>
  
  <p>EDIT:
  in another terminal i have to put cat file > (named_file)
  and my main program will read the input data. heres what the input data looks like</p>
  
  <p>3 3</p>
  
  <p>1 2 0</p>
  
  <p>0 2 0</p>
  
  <p>3 0 0</p>
  
  <p>first 2 numbers are grid information and player number, and after that is grid, but this a simplified version, ill be dealing with sizes over 100's of players and grids of over 1000's</p>