C library function - abort()

Advertisements


Description

The C library function void abort(void) abort the program execution and comes out directly from the place of the call.

Declaration

Following is the declaration for abort() function.

void abort(void)

Parameters

  • NA

Return Value

This function does not return any value.

Example

The following example shows the usage of abort() function.

#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);
}

Let us compile and run the above program, this will produce the following result it tries to open nofile.txt file which does not exist:

Going to open nofile.txt
Going to abort the program


Advertisements
Advertisements