C 庫函數 - abort()
描述
C 庫函數 void abort(void) 中止程式執行,直接從調用的地方跳出。
聲明
下麵是 abort() 函數的聲明。
void abort(void)
參數
- NA
返回值
該函數不返回任何值。
實例
下麵的實例演示了 abort() 函數的用法。
#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); }
讓我們編譯並運行上面的程式,這將產生以下結果,因為我們嘗試打開的檔 nofile.txt 是不存在的:
準備打開 nofile.txt 準備終止程式