C Exercises: Abort the current process
17. Process Abortion
Write a C program to abort the current process.
Sample Solution:
C Code:
#include<stdio.h> // Include the standard input/output header file.
#include<stdlib.h> // Include the standard library header file.
int main () // Start of the main function.
{
FILE * FilePtr; // Declare a pointer to a file 'FilePtr'.
FilePtr= fopen ("myfile.txt","r"); // Open the file "myfile.txt" in read mode.
if (FilePtr == NULL) // Check if the file could not be opened.
{
fputs ("\n File does not exist or error, in opening the file.\n",stderr); // Print an error message.
abort(); // Terminate the program abnormally.
}
fclose (FilePtr); // Close the file.
return 0; // Return 0 to indicate successful execution of the program.
} // End of the main function.
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to trigger a process abort using abort() when a specific error condition is detected.
- Write a C program to simulate a fatal error by calling abort() upon invalid user input.
- Write a C program to deliberately call abort() when a file open operation fails and log the error.
- Write a C program to register a signal handler for SIGABRT and then invoke abort() to test the handler.
Go to:
PREV : Absolute Value of an Integer.
NEXT : Demonstrating the 'long' Keyword.
C Programming Code Editor:
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.