title: C, check if a file exists without being able to read/write possible?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c-cross-platform">What’s the best way to check if a file exists in C? (cross platform)</a>  </p>
  </blockquote>
  
  
  
  <p>i would like to check if a file exists or not. I changed the permissions of my testfile to "chmod -r somefile". However now it says that the file does not exist even though it does exist.</p>
  
  <p>So i assume if i dont have read permissions i cannot open the file with "fopen r". But that would mean that there is no easy way to tell if a file exists or cannot be read/written?</p>
  
  <p>Or am i missing something? Any help would be great.</p>
  
  <p>Thanks!</p>
  
  <pre><code>int doesFileExist(const char* filename)
  {
    FILE* fptr = fopen(filename, "r");
    if (fptr != NULL)
    {
      fclose(fptr);
      printf("File exists\n");
      return 1;
    }
    printf("File doesnt exist\n");
    return 0;
  }
  </code></pre>
  
  <p>Update: Thanks guys for these great links and explanations!</p>