From: firewind Newsgroups: comp.os.msdos.djgpp Subject: Re: Checking to see if I file exists Date: 24 Oct 1997 02:59:46 GMT Organization: Netcom Lines: 32 Message-ID: <62p2v2$1am@sjx-ixn10.ix.netcom.com> References: <199710210043 DOT RAA15253 AT adit DOT ap DOT net> <344F2B84 DOT 7979 AT dcs DOT gla DOT ac DOT uk> NNTP-Posting-Host: elp-tx1-04.ix.netcom.com Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Campbell Allan 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) -]