fopen()
There is no absolutely correct way to check whether a file exists
or not, since the security rules of the OS may not permit you
to know whether the file exists or not. But fopen() in "r"
mode gives you a definite YES or a probable NO.
On the other hand, the information may not be particularly useful.
You can write a function that attempts to fopen() a file, records
whether it succeeded, fclose()s the file, and returns the result of
the fopen(). The file may no longer exist by the time you try to use
it. For that matter, an fopen() call has to specify whether the file
is to be opened in text or binary mode. If the OS makes a strong
distinction between text and binary files, it may be that one will
succeed and the other will fail. And, of course, knowing that a file
exists doesn't guarantee that you can do anything with it.
Presumably you want to know whether a file exists so you can find out
whether you can do something with it. Often a better approach is to
go ahead and try to do what you wanted to do in the first place, and
handle any errors that result.