#include 「errno.h」

    技术2025-01-14  47

    打印错误信息的函数是什么 #include <stdio.h> #include <errno.h> #include <string.h> /* @前提须知: 1:C 标准库的errno.h头文件定义了整数变量:errno 2:errno初始为int 0; 3:error == x --> x类型的错误 Value of errno: 0 Error opening file: No error Value of errno: 1 Error opening file: Operation not permitted Value of errno: 2 Error opening file: No such file or directory Value of errno: 3 Error opening file: No such process ......... @errno宏的使用: { 1:extern --> 在其余文件调用该变量! 2:注意fprintf的使用,因为大部分程序不是控制台程序 3:fopen的路径需要与该.c文件相同路径 4:fopen返回类型是file类型 } @strerror的使用 { 打印errno的错误描述! } */ extern int errno; void errno_use() { FILE* text; text = fopen("1.txt","r"); if (text == NULL) { //打印错误类型 printf("\nopen error: %d\n", errno); //打印错误描述 printf("\nerror discription:%s\n", strerror(errno)); } else { printf("open sucess!"); fclose(text); } }
    Processed: 0.009, SQL: 9