Perror prints system error messages
Void perror (const char * s );
Prototype in stdio. h
Note:
Perror prints the error message to the stderr stream (via the console), indicating the system error information of the last library program.
First
Print the string parameter, and then
Is a colon, and then
Is the information corresponding to the current errno value, and the last line feed
. Specify that the transmitted file name is a string parameter.
Use the global variable sys_errlist (defined in stdio. H, extern char * _ cdecl sys_errlist [];)
Array of characters for obtaining information, errno (
Defined in stdio. H,
Extern int _ cdecl errno;) can be used as the subscript of the array to find the string corresponding to the error code. The string itself does not include a line break.
Global variable sys_nerr
(Defined in stdio. H,
Extern int _ cdecl sys_nerr;) contains the number of items in the array
Perror does not return values.
Applicable to Unix systems, defined in ANSI C
# Include <stdio. h>
Int main ()
{
File * FP;
Fp = fopen ("perror. dat", "R ");
If (! FP)
Perror ("unable to open the file ");
Return 0;
}