www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/13/11:08:40

From: Timo Saarinen <Timo DOT Saarinen AT uku DOT fi>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: catching a CTRL C / Just for Eli and DJ Delorie
Date: Mon, 13 Jan 1997 09:42:52 -0800
Organization: University of Kuopio / Library
Lines: 45
Message-ID: <32DA741C.60A1@uku.fi>
References: <5b9r78$h1f AT nntp DOT novia DOT net> <5bb23s$6oq AT nntp DOT novia DOT net>
Reply-To: Timo DOT Saarinen AT uku DOT fi
NNTP-Posting-Host: kryssi8.uku.fi
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Alaric Dailey wrote:

[...]
>  The explaination is simple the program should do the while loop until you
> hit ^C in which case it will call the function "terminate", any help
> would be appreciated since I have not yet tried the change to "signal" yet
> I will go see if that helps at all.
> 
> TTFN

Hi, 

I made some modifications to your source code and now it works well.
Here it is:

#include <stdio.h>
#include <signal.h>

void terminate(int a);

void ctrlbrk(void (*fptr)(int))
{
  signal (SIGINT, fptr);
}

void terminate(int a)
{
  puts("I am doing clean up and exiting because you hit Contro-C");
  exit (0);
}

int main()
{
  ctrlbrk(terminate); // when ^c is hit call the cleanup funtion
  while (1)
  puts("I am running on and on and on and on!");
}

Timo

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Timo Saarinen, University of Kuopio / Library, Finland
 E-mail:      	Timo DOT Saarinen AT uku DOT fi
 Homepage:	http://www.lut.fi/~tsaarine/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019