#include <stdio.h>
void perror( const char *message );
#include <string.h>
char *strerror( int errnum );
FILE *open_file( char *filename )
{
FILE *stream;
errno = 0;
stream = fopen( filename, "r" );
if (stream == NULL) {
printf("------perror() output------\n");
perror("open");
printf("------strerror() output-------\n");
printf("can not open the file %s. reason: %s\n", filename,
strerror(errno));
exit(-1);
} else return stream;
}
int main()
{
char *filename = "test-e";
open_file( filename );
return 0;
}
beyes@linux-beyes:~/C> ./error.exe
------perror() output------
open: No such file or directory
------strerror() output-------
can not open the file test-e. reason: No such file or directory
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |