I have this code that's supposed to read from a text file and print its content but I keep getting "Unable to open file."
#include <stdio.h>
#include <string.h>
#define MAX 4000
int main(void)
{
FILE *bkptr;
char buffer[MAX];
bkptr = fopen("defoe-robinson-103.txt", "r");
// If file dow not open
if (bkptr == NULL) {
puts("Unable to open file.");
}
// If file open
else {
// Read each line form file until EOF
while (fgets(buffer, MAX, bkptr)) {
// Print the line
puts(buffer);
}
// Close the file
fclose(bkptr);
}
}