PERROR

要将用户可读的错误消息打印到 stderr,请从<stdio.h>调用 perror

int main(int argc, char *argv[])
{
   FILE *fout;

   if ((fout = fopen(argv[1], "w")) == NULL) {
      perror("fopen: Could not open file for writing");
      return EXIT_FAILURE;
   }
return EXIT_SUCCESS;
}

这将打印有关 errno 当前值的错误消息。