Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is abort_handler_s in C?

Behzad Ahmad

We use the abort_handler_s function to write an error message on the defined format on the standard error stream stderr. We use this as a parameter of the function set_constraint_handler_s.

It outputs it to stderr, which is displayed on the terminal. After output to stdout, abort_handler_s calls the abort function.

Library

#include<stdlib.h>

Syntax

void abort_handler_s
(
  const char * restrict message,
  void * restrict temp,
  errno_t error
);

Parameters

message - A pointer to the message which describes the error.

temp - A pointer to the data given.

error - Error code.

Return value

This function has no return value.

Code

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
  char* ptr = NULL;
  set_constraint_handler_s(abort_handler_s);
  gets_s(ptr, 9); 
  return 0;
}

In this piece of code, we initialize a pointer to an array and store NULL in it.

Then, we call the set_constraint_handler_s function and pass the abort_handler_s as a parameter.

Next, we call the gets_s function.

The benefit of using gets_s function is that no matter how many characters the user inputs, only the first 9 characters are stored in the ptr.

RELATED TAGS

c

CONTRIBUTOR

Behzad Ahmad
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring