title: how to detect a file is opened or not in c
body: <p>I'm trying to output some string on a txt file by using c program</p>
  
  <p>however, I need to see if the I have the permission to write on the txt file, if not, I need to print out the error message? However, I don't know how to detect if I successfully open a file or not, could someone help me about this? thanks</p>
  
  <p>The code is like this</p>
  
  <pre><code>File *file = fopen("text.txt", "a");
  
  fprintf(file, "Successfully wrote to the file.");
  
  //TO DO (Which I don't know how to do this)
  //If dont have write permission to text.txt, i.e. open was failed
  //print an error message and the numeric error number
  </code></pre>
  
  <p>Thank you for anyone helps, thanks a lot</p>