20-errno.c 290 B

123456789101112131415
  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <string.h>
  4. int main() {
  5. FILE *file = fopen("nonexistent.txt", "r");
  6. if (file == NULL) {
  7. printf("Error opening file: %s\n", strerror(errno));
  8. } else {
  9. // 文件操作
  10. fclose(file);
  11. }
  12. return 0;
  13. }