Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4 |
both |
#include <regex.h>
size_t regerror(int errcode, const regex_t *_restrict_preg,
char *_restrict_errbuf, size_t errbuf_size);
Finds the description for errcode. (For a description of regular expressions, see Regular expressions.)
regerror() returns the integer value that is the size of the buffer needed to hold the generated description string for the error condition corresponding to errcode.
The LC_SYNTAX characters in the messages will be converted to the code points from the current LC_SYNTAX category.
⁄* CELEBR08
This example compiles an invalid regular expression, and
print error message ®error..
*⁄
#include <regex.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
main() {
regex_t preg;
char *pattern = "a[missing.bracket";
int rc;
char buffer[100];
if ((rc = regcomp(&preg, pattern, REG_EXTENDED)) != 0) {
regerror(rc, &preg, buffer, 100);
printf("regcomp() failed with '%s'\n", buffer);
exit(1);
}
}