w3resource

C abort() function

C abort() function - Stop a process

Syntax abort() function

void abort(void)

The abort() function is used to terminate abnormal process and returns control to the host environment. In the same way that exit() deletes buffers and closes open files before terminating the program, abort() does the same.

Parameters abort() function

NA

Return value from abort()

  • This function does not return any value.

Example: abort() function

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

#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
   FILE *ptr;
 
   if ((ptr = fopen("user/test.txt", "r")) == NULL)
   {
      perror("Could not open data file!");
      abort();
   }
}

Output:

Could not open data file!: No such file or directory

C Programming Code Editor:

Previous C Programming: C realloc()
Next C Programming: C atexit()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/c-programming/stdlib/c-abort.php