Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language%20in%20C%20Interview%20Questions%20and%20Answers

Question: The access( ) function...

Answer: The access( ) function checks for the existence of a file and also determines whether it can be read, written to or executed. This function takes two arguments the filename and an integer indicating the access mode. The values 6, 4, 2, and 1 checks for read/write, read, write and execute permission of a given file, whereas value 0 checks whether the file exists or not. Following program demonstrates how we can use access( ) function to check if a given file exists.

#include <io.h>

main( )
{
char fname[67] ;

printf ( "nEnter name of file to open" ) ;
gets ( fname ) ;

if ( access ( fname, 0 ) != 0 )
{
printf ( "nFile does not exist." ) ;
return ;
}
}

Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook