Add error handling for the case of failed to open file by fopen()