// TOPIC : ERROR HANDLING
//errno=========== 2
//strerror
//perror()
//EXIT_SUCCESS
//EXIT_FAILURE
#include stdio.h
//need new header file for handling errors
#include errno.h
#include stdlib.h
// now run the program
int main()
{
//CREATE FILE POINTER
FILE *fp;
// TRY TO OPEN THE FILE WITH READ MODE (ASCII OR BINARY FILE )
fp=fopen("filenotexist.txt","r"); // Actually the file is not present in debug folder
// Due to that the program will throws an error message
//we are going to find the correspoinding error code for that
printf("Error Number = \t%d\n",errno);
// NEXT WE ARE GOING TO FILE THE EXACT ERROR TYPE USING STRERROR() FUNCTION
printf("\nString Error = \t%s",strerror(errno));
// NEXT USING PASSERROR FUNCTION WE ARE GOING TO DISPLAY THE LATEST ERROR OCCURED
perror("\n Last Error Occured = "); // NO NEED FOR VARIABLES HERE
//EXIT_FAILURE & EXIT_SUCCESS WILL NOT DISPLAY ANYTHING IN OUTPUT TERMINAL
exit(EXIT_SUCCESS); // TO USE EXIT_FAILURE & EXIT_SUCCESS HAVE TO INCLUDE STDLIB IN HEADER
//EXIT_SUCCESS WILL NOT TERMINATE YOUR OUTPUT SCREEN.
//instead of using non zero error codes in exit() function you can use the above two keywords
return 0;
}
//RUN THE PROGRAM CTRL+F5