Given a file path, we have to check whether a specified file exist or not using the stat() function.
The source code to check a specified file exists or not using the stat() function is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
// C program to check a specified file exist or not
// using stat() function
struct stat buff;
int isFileExist = 0;
isFileExist = stat("includehelp.txt",&buff);
if(isFileExist == 0)
printf("file does not exists.\n");
Here, we checked file "includehelp.txt" exists in the current directory or not using the stat() function. Then printed the appropriate message on the console screen.
total answers (1)
start bookmarking useful questions and collections and save it into your
own study-lists, login now to start creating your own collections.