C - strerror() function
C strerror() function - Get error message string
Syntax:
char *strerror(int errnum)
The strerror() function is used to map the error number in errnum to an error message string.
Parameters:
Name | Description | Required /Optional |
---|---|---|
errnum | Error number. | Required |
Return value from strerror()
- Returns a pointer to the string.
Example: strerror() function.
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main()
{
FILE *stream;
if ((stream = fopen("testt.txt", "r")) == NULL)
printf("%s \n", strerror(errno));
return 0;
}
Output:
No such file or directory
Example: First fifty system error messages using strerror() function
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main()
{
FILE *stream;
if ((stream = fopen("testt.txt", "r")) == NULL)
printf("%s \n", strerror(errno));
return 0;
}
Output:
First 50 system error messages: 1: Operation not permitted 2: No such file or directory 3: No such process 4: Interrupted function call 5: Input/output error 6: No such device or address 7: Arg list too long 8: Exec format error 9: Bad file descriptor 10: No child processes 11: Resource temporarily unavailable 12: Not enough space 13: Permission denied 14: Bad address 15: Unknown error 16: Resource device 17: File exists 18: Improper link 19: No such device 20: Not a directory 21: Is a directory 22: Invalid argument 23: Too many open files in system 24: Too many open files 25: Inappropriate I/O control operation 26: Unknown error 27: File too large 28: No space left on device 29: Invalid seek 30: Read-only file system 31: Too many links 32: Broken pipe 33: Domain error 34: Result too large 35: Unknown error 36: Resource deadlock avoided 37: Unknown error 38: Filename too long 39: No locks available 40: Function not implemented 41: Directory not empty 42: Illegal byte sequence 43: Unknown error 44: Unknown error 45: Unknown error 46: Unknown error 47: Unknown error 48: Unknown error 49: Unknown error 50: Unknown error
C Programming Code Editor:
Previous C Programming: C strcspn()
Next C Programming:C strlen()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/c-programming/string/c-strerror.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics