C 庫函數(shù) - abort()

C 標準庫 - <stdlib.h> C 標準庫 - <stdlib.h>

描述

C 庫函數(shù) void abort(void) 中止程序執(zhí)行,直接從調(diào)用的地方跳出。

聲明

下面是 abort() 函數(shù)的聲明。

void abort(void)

參數(shù)

  • NA

返回值

該函數(shù)不返回任何值。

實例

下面的實例演示了 abort() 函數(shù)的用法。

#include <stdio.h>
#include <stdlib.h>

int main ()
{
   FILE *fp;
   
   printf("準備打開 nofile.txt\n");
   fp = fopen( "nofile.txt","r" );
   if(fp == NULL)
   {
      printf("準備終止程序\n");
      abort();
   }
   printf("準備關閉 nofile.txt\n");
   fclose(fp);
   
   return(0);
}

讓我們編譯并運行上面的程序,這將產(chǎn)生以下結(jié)果,因為我們嘗試打開的文件 nofile.txt 是不存在的:

準備打開 nofile.txt
準備終止程序

C 標準庫 - <stdlib.h> C 標準庫 - <stdlib.h>