/* Demonstration of error handling with perror() and errno. */ #include #include #include main() { FILE *fp; char filename[80]; printf("Enter filename: "); gets(filename); if (( fp = fopen(filename, "r")) == NULL) { perror("You goofed!"); printf("errno = %d.", errno); exit(1); } else { puts("File opened for reading."); fclose(fp); } return(0); }