Easy Tutorial
❮ C Function Fopen C Function Ldexp ❯

C Library Function - abort()

C Standard Library - <stdlib.h>

Description

The C library function void abort(void) terminates the program execution by jumping out directly from the point of call.

Declaration

Below is the declaration for the abort() function.

void abort(void)

Parameters

Return Value

This function does not return any value.

Example

The following example demonstrates the use of the abort() function.

#include <stdio.h>
#include <stdlib.h>

int main ()
{
   FILE *fp;

   printf("Preparing to open nofile.txt\n");
   fp = fopen( "nofile.txt","r" );
   if(fp == NULL)
   {
      printf("Preparing to abort the program\n");
      abort();
   }
   printf("Preparing to close nofile.txt\n");
   fclose(fp);

   return(0);
}

Let's compile and run the above program, which will produce the following result because the file nofile.txt we tried to open does not exist:

Preparing to open nofile.txt
Preparing to abort the program

C Standard Library - <stdlib.h>

❮ C Function Fopen C Function Ldexp ❯