Example: Checking the errno Value for the fopen() Function

The following figure shows how to check the errno value for the fopen() function.
Figure 1. ILE C Source to Check the errno Value for fopen()
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
void main(void)
{
   FILE *fp;
   errno = 0;
   fp = fopen("Nofile", "r");
   if ( errno != 0 ) 
   {
     perror("Error occurred while opening file.\n");
     exit(1);
   }
}