C Exercises: Abort the current process
C Variable Type : Exercise-17 with Solution
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 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.
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-exercises/variable-type/c-variable-type-exercises-17.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics