fopen actually tries to open the file, which you can't do if you don't have read access. In order to check whether the file exists without opening it, use stat; stat gives you metadata about the file, and requires only read access to the directory containing the file, not the file itself.
int doesFileExist(const char *filename) {
struct stat st;
int result = stat(filename, &st);
return result == 0;
}
You could get fancier by checking errno if result is not 0; if errno is ENOENT then the file does not exist, if it is ENOTDIR then part of the path you provided is not a directory, if it's EACCESS then you didn't have read permission on one of the directories in the path and so stat can't give you an answer, and so on.
Also, be aware that if you're on a platform with symlinks (any Unix-like, or Windows Vista or later), that you should be aware of whether you are querying about the symlink or the file it points to. If you call stat, then you are asking about the file it points to; if you have a symlink dir/link which points to other/file, then stat will return results about other/file (which is usually what you want, since that's what you would get if you opened the file). However, if you are curious about the link itself (if you want to know "does dir/link exist, even if other/file does not?"), then you should use lstat().
stat() works on Windows as a compatibility wrapper (they prefer you use _stat(), and will warn if you don't), but it's generally better to use the native platform APIs. On Windows, you should probably use GetFileAttributes():
int doesFileExist(const char *filename) {
return GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES;
}