Q:
C program to check a specified file exists or not using the stat() function
belongs to collection: File Handling Examples Programs in C language
File Handling Examples Programs in C language
- C program to find number of lines in a file
- C program to create a text file using file handling, example of fopen, fclose
- C program to create, write and read text in/from file
- C program to print given number of lines of a file (like head command in Linux)
- C program to print contents in reverse order of a file (just like TAC command in Linux)
- C program to compare contents of two files
- C program to copy number of bytes from specific offset to another file
- C - Read Content of a File using getc() using C Program
- C - Convert All Characters in Upper Case of a File using C Program
- C program to delete a specified file using remove() function
- C program to delete a specified file using the system() function
- C program to remove a specified empty directory using the remove() function
- C program to remove an empty directory
- C program to remove a non-empty directory using the system() function
- C program to check a given filename is a directory or not
- C program to remove a specific line from the text file
- C program to replace the specified line in an existing text file
- C program to append the content of one file to the end of another file
- C program to print the list of files of a directory
- C program to print the list of files and subdirectories of the current directory
- C program to check a specified directory exists or not
- C program to check a specified file exists or not
- C program to check a specified file exists or not using the stat() function
- C program to check a specified file exists or not using the access() function
- C program to check a specified file has read, write, and execute permission or not
- C program to create a directory using mkdir() function
- C program to create a directory using system() function
- C program to remove an empty directory using rmdir() function
- C program to rename a file using the rename() function
- C program to rename a file using the system() function
- C program to change the permissions of file using system() function
- C program to capitalize the first letter of every word in a file
Given a file path, we have to check whether a specified file exist or not using the stat() function.
Program:
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.
Output:
Explanation:
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.
need an explanation for this answer? contact us directly to get an explanation for this answer