abort函数应用举例,简单说明下就可以?

来源:百度知道 编辑:UC知道 时间:2024/05/19 12:59:26
最好是给带一个小的程序,但是要在实际的用途中用到,不要仅仅告诉我是结束一个程序用的。

MS VC++ 自带的例子:

Example

/* ABORT.C: This program tries to open a
* file and aborts if the attempt fails.
[这个程序试图打开一个文件,但是失败“流产”了。]
*/

#include <stdio.h>
#include <stdlib.h>
void main( void )
{
FILE *stream;
if( (stream = fopen( "NOSUCHF.ILE", "r" )) == NULL )
{
perror( "Couldn't open file" );
abort();
}
else
fclose( stream );
}

输出:
Couldn't open file: No such file or directory
abnormal program termination

qw

#include <stdio.h>
#include <stdlib.h>
void main( void )
{
FILE *stream;
if( (stream = fopen( \"NOSUCHF.ILE\", \"r\" )) == NULL )
{
perror( \"Couldn\'t open file\" );
abort();
}
else
fclose( stream );
}