C Programming
Computer Programming

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



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

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

# include < stdio.h >
# include < sys/stat.h >
int   main( )
{

struct stat buff ;
int isFileExist = 0 ;
char filename[15] ;
printf("\n Enter the filename to be opened : ") ;
scanf("%s", filename) ;
isFileExist = stat(filename, &buff ) ;
if(isFileExist == 0)
{
      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 stat() function