Mail Archives: djgpp/1997/10/26/16:17:36
Campbell Allan <allanca AT dcs DOT gla DOT ac DOT uk> wrote:
> Nate Eldredge wrote:
> > Try the very confusingly :) named function __file_exists(). If you want to
> > be portable, use access() or stat().
> >
> What's wrong with trying to open the file as normal? I use fopen which
> returns a pointer to FILE. If the file doesn't exist or can't be
> read/written to for some reason then a NULL is returned instead of the
> pointer. ie.
> FILE *fp;
> fp=fopen("myfile.dat","br");
> if (fp==NULL)
> {
> printf("Error datafile does not exist!\n");
> exit(EXIT_FAILURE);
> }
> You should always do this when reading files to make sure your program
> doesn't crash out without telling the user why.
This could be misleading though... fopen() can fail for many more reasons
than simply, 'file does not exist'...
--
[- firewind -]
[- email: firewind AT metroid DOT dyn DOT ml DOT org (home), firewind AT aurdev DOT com (work) -]
[- "You're just jealous because the voices talk to -me-." -]
[- Have a good day, and enjoy your C. -]
[- (on a crusade of grumpiness where grumpiness is due) -]
- Raw text -