|
File Operations
This example shows how to check whether a file exist or not and
writing text strings to file.
08 | char * file_path = "C:\\file_ops.txt" ; |
11 | status = access(file_path, 0); |
13 | printf ( "File (%s) exists\n" , file_path); |
15 | printf ( "File (%s) doesn't exist\n" , file_path); |
19 | FILE *fp = fopen (file_path, "w" ); |
20 | fprintf (fp, "BE THE CODER" ); |
23 | status = access(file_path, 0); |
25 | printf ( "File (%s) exists\n" , file_path); |
27 | printf ( "File (%s) doesn't exist\n" , file_path); |
|
It gives the following output,
File (C:\file_ops.txt) doesn't exist
File (C:\file_ops.txt) exists
|
|