Re: File exist
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 18 Apr 2006 22:39:40 +0100
Kenneth Brody wrote:
Keith Thompson wrote:
[...]
Usually the best approach is to try to open the file, and handle the
error if the attempt fails. Providing information about *why* it
failed can be useful, but it isn't absolutely necessary, and it can't
be done portably.
Isn't this portable?
... proper #include's, etc. implied ...
errno=0;
f = fopen(filename,mode);
if ( f == NULL )
{
if ( errno != 0 )
perror(filename);
else
fprintf(stderr,"fopen() of %s failed.\n",filename);
exit(EXIT_FAILURE);
}
It's portable, but it might always print out "fopen() of %s failed.\n" and never give a reason on some implementations.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
.
- Follow-Ups:
- Re: File exist
- From: Kenneth Brody
- Re: File exist
- References:
- File exist
- From: paytam
- Re: File exist
- From: ed
- Re: File exist
- From: Keith Thompson
- Re: File exist
- From: Claude Yih
- Re: File exist
- From: Flash Gordon
- Re: File exist
- From: Mr John FO Evans
- Re: File exist
- From: Keith Thompson
- Re: File exist
- From: Kenneth Brody
- File exist
- Prev by Date: Re: File exist
- Next by Date: Re: Different code behaviour in Unix & Windows
- Previous by thread: Re: File exist
- Next by thread: Re: File exist
- Index(es):
Relevant Pages
|