Hey everyone...
Is there any way to check if a file exists?
Hey everyone...
Is there any way to check if a file exists?
Check for existence when you try to open it perhaps? As in the following code, if opening returns NULL, it ain't where you're lookin for it, or can't be opened for some other reason.
Code:#include <stdio.h> int main(void) { FILE *in if ((in = fopen("\\AUTOEXEC.BAT", "r")) == NULL) { printf("Cannot open input file.\n"); return 1; } return 0; }
Here's one way of doing it:
Code:#include <stdio.h> int main () { FILE *fp; if ((fp=fopen("c:\\test.bin", "r")) == NULL) { printf("Blahhh"); } return 0; }
Last edited by jizzer; 04-25-2002 at 01:20 AM.