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.


C Exercises Flowchart: Abort the current process

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.

Follow us on Facebook and Twitter for latest update.