over 5 years ago
I am writing a program for error handling in c programming but I am confusing to choose best approach for handle error from if-else and switch-case.
Please explain with suitable example and guide me best approach.
Thanks in advance.
In C programming we don't have the error handling mechanism but at the point of view system programming language, it provides access at lower level in the form of return values. it can return -1 and NULL in any error and sets an error code errno is set which is global variable and indicates an error occurred during any function call. the various error codes defined in header file.
C programming language provides perror() and strerror() functions which can be used to display the text message associated with errno.
The Below code can represent the error using perror() and strerror() function if the file pointer value indicates to NULL that means the file not present in that location or not exist.
extern int errno ;
int main ()
FILE * pf;
pf = fopen ("unexist.txt", "rb");
if (pf == NULL)
errnum = errno;
fprintf(stderr, "Value of errno: %d\n", errno);
perror("Error printed by perror");
fprintf(stderr, "Error opening file: %s\n", strerror( errnum ));
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Terms of Service
| © copyright 2020 FindNerd.com. All rights reserved.
Sign up using