C Exercises: Abort the current process
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:
![C Exercises Flowchart: Abort the current process](https://www.w3resource.com/w3r_images/c-variable-type-exercises-flowchart-17.png)
C Programming Code Editor:
Previous: Write a C program to return the absolute value of an integer.
Next: Write a C program to demonstrate the working of keyword long.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics