abort() – C语言库函数
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 "); fp = fopen("nofile.txt","r");if(fp == NULL){ printf("Going to abort the program "); abort();} printf("Going to close nofile.txt "); fclose(fp);return(0);}
让我们编译和运行上面的程序,这将试图打开nofile.txt 文件不存在产生以下结果:
Going to open nofile.txt Going to abort the program