title: Using read() for reading a file in C
body: <p>My goal is to read the content of a file and print it to the screen</p>
  <p>So, I have a file called &quot;file.txt&quot;. I want to read it using the read() function and then print its contents.</p>
  <p>Here is the code that I have written so far:</p>
  <pre><code>
  int file = open(&quot;./file.txt&quot;,O_CREAT | O_WRONLY,0777); // added
  
  char buffer[50];
  printf(&quot;Reading file.txt\n&quot;);
  int bytes = read(file,buffer,sizeof(buffer));
  printf(&quot;Bytes read = %d\n&quot;,bytes);
  if(bytes &lt;=0 ){
    printf(&quot;file.txt\n impossible to read\n&quot;);   
  }else{
    printf(&quot;Read - %s \n&quot;,buffer);
  }
  
  close(file);
  </code></pre>
  <p>My code is not working. It returns bytes = -1.</p>
  <p>What is wrong with my code?</p>
  <p>In my file, I only have a sentence written or a single char. It's that simple just for testing.</p>