The strerror () function in C
The function char * strerror (int errnum) searches for an internal array for errnum error numbers and returns a pointer to a string of error messages.
The function char * strerror (int errnum) searches for an internal array for errnum error numbers and returns a pointer to a string of error messages.
Declaring strerror () function in C
Here is the declaration for strerror () in C:
char * strerror ( int errnum )
Parameters
errnum - Usually errno , describes the error number.
Returns the value
This function returns a pointer to the error string describing errnum error.
For example
The following C program illustrates the usage of strerror () in C:
#include #include #include int main () { FILE * fp ; fp = fopen ( "thuvienc.txt" , "r" ); if ( fp == NULL ) { printf ( "Error: %sn" , strerror ( errno )); } return ( 0 ); }
Compiling the C program will result (because we open a file that does not exist):
According to Tutorialspoint
Previous article: strcspn () function in C
Next lesson: strlen () function in C
Update 25 May 2019
You should read it
- The strlen () function in C
- The strchr () function in C
- The strcspn () function in C
- How to 'survive' with the stress of learning programming
- Strncat () function in C
- The strtok () function in C
- The strncpy () function in C
- Bookmark a few tricks to help you master a programming language
- Top 20 free programming learning websites need to bookmark immediately!
- Beginners of computer programming need to focus on what?
- The strspn () function in C
- Set of multiple choice questions about programming with P10 prize
Maybe you are interested
Nvidia just caused the 'blue screen of death' error for Windows Did you know: In addition to the blue screen, does Windows also have a 'dead' green screen? Ways to fix BSOD blue screen error How to find the cause of blue screen death and Minidump errors? How to create a blue screen of death (BSOD) to 'prank' friends Prevent 'blue screen errors' on Windows 8