I am trying to include statements that instruct the user a little bit more about why a file failed to open or close. What are some possible situations where a file would fail to open in write mode and what about failing to close?
FILE *fp;
if(!(fp = fopen("testing", "w")))
{
fprintf(stderr, "\nError %d: Loading from \"testing\" file failed: %s\n",
errno, strerror(errno));
printf("Add additional explanations here\n");
}
fclose(fp);
The error you can get from trying to open a file in write mode are OS specific. But it's basically that the owner or the user running the program don't have the rights to write to the file.
Same for the fclose, it's os specific but as it automatically execute a fflush, that is an operation that can fail when you don't have enough space on your disk for example.