title: Using read() system call
body: <p>For an assignment in class we were tasked with using the <code>read()</code> function to read a file containing numbers.  While I was able to read the numbers into a buffer I have been unable to move them from the buffer into a char *array so that they can be easily accessed and sorted.  Any advice is appreciated.</p>
  
  <pre><code>int readNumbers(int hexI, int MAX_FILENAME_LEN, int **array, char* fname) {
      int numberRead = 0, cap = 2;
      *array = (int *)malloc(cap*sizeof(int));
      int n;
      int filedesc = open(fname, O_RDONLY, 0);
      if(filedesc &lt; 0){
          printf("%s: %s\n", "COULD NOT OPEN", fname);
          return -1;
      }
      char * buff = malloc(512);
      buff[511] = '\0';
     while(n = read(filedesc, buff+totaln, 512 - totaln) &gt; 0) //Appears to loop only once
              totaln += n;
      int len = strlen(buff);
      for (int a = 0; a &lt; len; a++) {  //Dynamically allocates array according to input size
          if ((&amp;buff[a] != " ") &amp;&amp; (&amp;buff[a] != '\n'))
              numberRead++;
          if (numberRead &gt;= cap){
              cap = cap*2;
              *array = (int*)realloc(*array, cap*sizeof(int));
          }
      }
      int k = 0;
      while((int *)&amp;buff[k]){  //attempts to assign contents of buff to array
          array[k] = (int *)&amp;buff[k];
          k++;
      }
  }
  </code></pre>