Re: File exist
- From: Kenneth Brody <kenbrody@xxxxxxxxxxx>
- Date: Tue, 18 Apr 2006 16:40:32 -0400
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);
}
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@xxxxxxxxx>
.
- Follow-Ups:
- Re: File exist
- From: Flash Gordon
- Re: File exist
- From: Keith Thompson
- 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
- File exist
- Prev by Date: Re: Different code behaviour in Unix & Windows
- Next by Date: Re: First C Program, Problems getting serial data
- Previous by thread: Re: File exist
- Next by thread: Re: File exist
- Index(es):