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()



Follow us on Facebook and Twitter for latest update.

C Programming: Tips of the Day

What's the point of const pointers?

const is a tool which you should use in pursuit of a very important C++ concept:

Find bugs at compile-time, rather than run-time, by getting the compiler to enforce what you mean.

Even though it does not change the functionality, adding const generates a compiler error when you're doing things you didn't mean to do. Imagine the following typo:

void foo(int* ptr)
{
    ptr = 0;// oops, I meant *ptr = 0
}

If you use int* const, this would generate a compiler error because you're changing the value to ptr. Adding restrictions via syntax is a good thing in general. Just don't take it too far -- the example you gave is a case where most people don't bother using const.

Ref : https://bit.ly/33Cdn3Q