Syntax
#include <io.h> int access(char *pathname, int mode);Description
access determines whether the specified file exists and whether you can get access to it in the given mode. Possible values for the mode and their meaning in the access call are:
Value
access returns 0 if you can get access to the file in the specified mode. A return value of -1 shows that the file does not exist or is inaccessible in the given mode, and the system sets errno to one of the following values:
Value
This example checks for the existence of the file SAMPLE.DAT. If the file does not exist, it is created.
#include <io.h>#include <stdio.h> #include <stdlib.h> int main(void) { if (-1 == access("sample.dat", 00)) { printf("File sample.dat does not exist.\n"); printf("Creating sample.dat.\n"); system("echo Sample Program > sample.dat"); if (0 == access("sample.dat", 00)) printf("File sample.dat created.\n"); } else printf("File sample.dat exists.\n"); return 0; /**************************************************************************** The output should be: File sample.dat does not exist. Creating sample.dat. File sample.dat created. ****************************************************************************/ }Related Information