C-standard-library-c-function-abort
提供:Dev Guides
Cライブラリ関数-abort()
説明
Cライブラリ関数* void abort(void)*は、プログラムの実行を中止し、呼び出しの場所から直接出ます。
宣言
次に、abort()関数の宣言を示します。
void abort(void)
パラメーター
- *NA *
戻り値
この関数は値を返しません。
例
次の例は、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)