目录

void abort(void)

描述 (Description)

C库函数void abort(void)中止程序执行并直接从调用位置输出。

声明 (Declaration)

以下是abort()函数的声明。

void abort(void)

参数 (Parameters)

  • NA

返回值 (Return Value)

此函数不返回任何值。

例子 (Example)

以下示例显示了abort()函数的用法。

#include <stdio.h>
#include <stdlib.h>
int main () {
   FILE *fp;
   printf("Going to open nofile.txt\n");
   fp = fopen( "nofile.txt","r" );
   if(fp == NULL) {
      printf("Going to abort the program\n");
      abort();
   }
   printf("Going to close nofile.txt\n");
   fclose(fp);
   return(0);
}

让我们编译并运行上面的程序,当它试图打开不存在的nofile.txt文件时会产生以下结果 -

Going to open nofile.txt                                                    
Going to abort the program                                                  
Aborted (core dumped)
↑回到顶部↑
WIKI教程 @2018