w3resource logo


C Programming Exercises

C Exercises: Abort the current process

Secondary Nav

C Variable Type : Exercise-17 with Solution

Write a C program to abort the current process.

Expected Output :

 File does not exist or error, in opening the file.                                                           
timeout: the monitored command dumped core                                                                    
Aborted 

C Code:

#include<stdio.h>
#include<stdlib.h>

int main ()
	{
		FILE * FilePtr;
		FilePtr= fopen ("myfile.txt","r");

		if (FilePtr == NULL)
		{
			fputs ("\n File does not exist or error, in opening the file.\n",stderr);
			abort();
		}

		fclose (FilePtr);

		return 0;
	}

Solution

#include<stdio.h>
#include<stdlib.h>

int main ()
	{
		FILE * FilePtr;
		FilePtr= fopen ("myfile.txt","r");

		if (FilePtr == NULL)
		{
			fputs ("\n File does not exist or error, in opening the file.\n",stderr);
			abort();
		}

		fclose (FilePtr);

		return 0;
	}

Improve this sample solution and post your code through Disqus



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number