zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然C语言开发:错误处理

    #include <stdio.h>
    #include <errno.h>
    #include <string.h>
     
    extern int errno ;
     
    int main ()
    {
       FILE * pf;
       int errnum;
       pf = fopen ("unexist.txt", "rb");
       if (pf == NULL)
       {
          errnum = errno;
          fprintf(stderr, "错误号: %d
    ", errno);
          perror("通过 perror 输出错误");
          fprintf(stderr, "打开文件错误: %s
    ", strerror( errnum ));
       }
       else
       {
          fclose (pf);
       }
       return 0;
    }
    #include <stdio.h>
    #include <stdlib.h>
     
    main()
    {
       int dividend = 20;
       int divisor = 0;
       int quotient;
     
       if( divisor == 0){
          fprintf(stderr, "除数为 0 退出运行...
    ");
          exit(-1);
       }
       quotient = dividend / divisor;
       fprintf(stderr, "quotient 变量的值为 : %d
    ", quotient );
     
       exit(0);
    }
    #include <stdio.h>
    #include <stdlib.h>
     
    main()
    {
       int dividend = 20;
       int divisor = 5;
       int quotient;
     
       if( divisor == 0){
          fprintf(stderr, "除数为 0 退出运行...
    ");
          exit(EXIT_FAILURE);
       }
       quotient = dividend / divisor;
       fprintf(stderr, "quotient 变量的值为: %d
    ", quotient );
     
       exit(EXIT_SUCCESS);
    }
  • 相关阅读:
    Codeforces Round #319 (Div. 2) D
    因为网络请求是 异步的,
    ios真蛋疼,
    单例模式的两种实现,
    jump, jump,
    一点 误删,
    关于代理,
    button上的两个手势,
    数据,
    header 的蓝色,
  • 原文地址:https://www.cnblogs.com/tszr/p/10968931.html
Copyright © 2011-2022 走看看