file-handling · beginner · ~15 min
Open a file and check the result of fopen.
Check whether a file can be opened for reading — the simplest use of fopen's return value.
Implement int file_readable(const char *path) that returns 1 if the file at path can be opened for reading (then closes it again), and 0 otherwise.
path: filename of a file the grader creates in the working directory.
Return 1 if fopen succeeds, 0 if it fails (missing or unreadable file).
existing file -> 1
missing file -> 0
path: file to test.
1 if openable for reading, else 0.
Close the file if it opened.
#include <stdio.h>
int file_readable(const char *path) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.