C Programming
Computer Programming

C file handling program to check a specified file exists or not using the access() function



Write C file handling program to check a specified file exists or not using the access() function

\* C file handling program to check a specified file exists or not using the access() function *\

# include < stdio.h >
# include < unistd.h >
int   main( )
{

int isFileExist = 0 ;
char filename[15] ;
printf("\n Enter the filename to be opened : ") ;
scanf("%s", filename) ;

isFileExist = access(filename, F_OK) ;
if (isFileExist != -1)
{
      printf(" file exists !\n") ;
      return 1 ;
}

printf(" file does not exists !\n") ;
return 0 ;

}

Output of Program :

Output of C file handling program to check a specified file exists or not using the access() function