title: Contents of file not being printed in terminal
body: <p>Hi I am trying to read from a file and print it on terminal. But <code>fwrite()</code> does not print anything. Can anyone please help! I cannot see the output from the file on the terminal. After debugging all I can see is program is not entering into while loop used before <code>fwrite()</code>.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  
  #define BUF_SIZE 128
  
  int main(int argc, char* argv[]) 
  {
      int BATT_fd, ret_write, ret_read, i;
      char buffer[BUF_SIZE];      
  
      if(argc != 2)
      {
          printf ("\nUsage: cp file1 file2\n");
          return 1;
      }
  
      BATT_fd = open (argv [1], O_RDWR | O_CREAT, S_IRWXU);
  
      if (BATT_fd == -1) 
      {
          perror ("open");
          return 2;
      }
  
   printf("\n file opened successfully with file desc %d\n", BATT_fd);
   printf("enter data into file\n");
   scanf("%[^\n]", buffer);
  
       if((ret_write = write (BATT_fd, &amp;buffer, BUF_SIZE)) == 0)
       { 
           printf("nothing is write");    
       }
       else if((ret_write = write (BATT_fd, &amp;buffer, BUF_SIZE)) == -1)
       { 
           printf("write error"); 
       }
       else
       {
           printf("wrote %d characters to file\n", ret_write);
           printf("address writeen is %x\n", buffer[i]);
       }
  
       if((ret_read = read(BATT_fd, &amp;buffer, BUF_SIZE)) &gt; 0)
       { 
          perror("read"); 
          return 4;
       }
       else
       {
          while((ret_read = read (BATT_fd, &amp;buffer, BUF_SIZE)) &gt; 0)
          {
              fwrite(buffer, 1, ret_read, stdout);
          }
       }
  
   close (BATT_fd);
  
   return 0;
  }
  </code></pre>
  
  <p>output:</p>
  
  <p><img src="https://i.stack.imgur.com/aJSvv.png" alt="enter image description here"></p>