Using the function access, the header file is IO.h, the prototype:
int access (const char *filename, int amode);
A amode parameter of 0 indicates the existence of the check file, if the file exists, returns 0, does not exist, returns-1.
This function can also check other file attributes:
06 Checking Read and Write permissions
04 Checking Read Permissions
02 Checking Write permissions
01 Checking Execution Permissions
00 checking the existence of files
Experiment successfully under UNIX and VC.
The advantage is that fopen (.., "R") is not good, and when no Read permission is lost.
And this even if the file does not have Read permission, you can also determine whether the file exists in the
There is a return of 0, there is no return-1
#include <stdio.h>
int main ()
{
printf ("%d", Access ("111", 0));
--------------------------------------------------------------------------------------------
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
void Main (void)
{
/* Check for existence */
if (_access ("Access. C ", 0))! =-1)
{
printf ("File ACCESS. C exists\n ");
/* Check for Write permission */
if (_access ("Access. C ", 2))! =-1)
printf ("File ACCESS. C has write permission\n ");
}
}
Output
File ACCESS. C exists
File ACCESS. C has Write permission
C language to determine whether a file exists