title: How to open a file for reading in C?
body: <p>There is this thing that gives me headaches in C programming when I deal with reading from files.</p>
  
  <p>I do not understand the difference between these 2 methods: </p>
  
  <pre><code>FILE *fd;
  fd=fopen(name,"r");  // "r" for reading from file, "w" for writing to file
                        //"a" to edit the file
  </code></pre>
  
  <p>fd returns NULL if the file can't be open, right?</p>
  
  <p>The second method that i use is:</p>
  
  <pre><code>int fd;
  fd=open(name,O_RDONLY); 
  </code></pre>
  
  <p>fd would be -1 if an error occurs at opening the file.</p>
  
  <p>Would anyone be kind enough to explain this to me?
  Thanks in advance:)</p>