title: copy whole of a file into memory using mmap
body: <p>i want to copy whole of a file to memory using mmap in C.i write this code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/mman.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;errno.h&gt;
  int main(int arg, char *argv[])
  {
      char c ;
      int numOfWs = 0 ;
      int numOfPr = 0 ;
      int numberOfCharacters ;
      int i=0;
      int k;
      int pageSize = getpagesize();
      char *data;
      float wsP = 0;
      float prP = 0;
      int fp = open("2.txt", O_RDWR);
      data = mmap((caddr_t)0, pageSize, PROT_READ, MAP_SHARED, fp,pageSize);
      printf("%s\n", data);
      exit(0);
  }
  </code></pre>
  
  <p>when i execute the code i get the <code>Bus error</code> message.
  next, i want to iterate this copied file and do some thing on it.
  how can i copy the file correctly?</p>