(e-mail address removed) opined:
Hi all
Can anyone tell me how can I check that a file exist or no.I mean
when you use this commands
FILE *fp;
if(!fp)
//Could not open the file
doen't show why it can not open it,may be the file doesn't exist.Now
tell me what should I do!
You can try reading `errno` (from <errno.h>) do get to the error code,
provided your implementation gives you one, and it's sensible (it's
not required by the Standard to do that). You'd have to set `errno` to
0 before calling `fopen()`, as library functions never do that. You
should consult documentation that came with your C compiler to see
what `errno` codes are available, and whether they can help you.
If your implementation does set useful error codes, you can then use
`strerror()` from <string.h> to get a huan-readable error string, or
`perror()` from <stdio.h>. Look them up in your manual.
Again, if your implementation does not provide sensible error
codes/messages, you're out in the cold. OTH, relying on your
implementation error codes/messages is more likely than not to make
your code non-portable.
--
That's a city in Bosnia. Right?
(Discussion in comp.os.linux.misc on the intuitiveness of commands.)
<
http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>