title: C: System calls and pointers to reverse a file
body: <p>Solved. Thanks lutogniew.....just over complicating it... </p>
  
  <p>So I am having some trouble with a homework assignment. The assignment is to take in a file (using only system calls), reverse it and write an output file with that reversed data on it (ASCII only). A catch is that the reverse section has to be done with pointers. I did the following below, which does work. However, it does not use pointers to reverse. </p>
  
  <p>My question I guess, is how can I access something like data[] using pointers? Or, how can I read from the file into it. Everything I tried (mostly char**) only reads in null.</p>
  
  <p>Any help would be much appreciated. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  
  int main(void)
  {
      int i = 0; 
      int fileOut = open("output.txt", O_WRONLY | O_APPEND);
      int fileIn = open("input.txt", O_RDONLY);
  
      int start = lseek(fileIn, 0 , SEEK_CUR);
      int end = lseek(fileIn, 0 , SEEK_END);
      int restart = lseek(fileIn, 0-end , SEEK_CUR);
  
      char data[end];
      char reverseData[end];
      read(fileIn, data, end);
      for(i = 0; i&lt; end; i++){
          reverseData[i] = data[end-(i+1)];
      }
  
      write(fileOut, reverseData, end);
  
      return 0;
  }
  </code></pre>