Start function when 'ctrl-c' are pressed

How do I start a function when I press 'ctrl-c' on the keyboard. Im using Borland C++ 5.02 (programing in windows).
Is it something in the DEFINE_RESPONSE_TABLE1 ??
Thanks!
bert1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
You'll have to install your own signal handling routines, e.g. by using



void    __cdecl     StopHdl         (   int nSig)
{
  // code goes here, will be executed when CTRL+C is pressed
}


    signal  (   SIGINT,     StopHdl);
    signal  (   SIGBREAK,   StopHdl);

0
KangaRooCommented:
Depends on compiler. For Borland it is

  void ctrlbrk(int (*handler)(void));

include <dos.h> for this function.
0
KangaRooCommented:
A sorry, misread the question. Please disregard my previous comment.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

bert1Author Commented:
Can you please specify a bit more .... I dont get it to work!

Thanks!
0
jkrCommented:
Hmm, there's hardly more to elaborate ;-)

What problems are you facing?
0
bert1Author Commented:
Where should I put    
signal  (   SIGINT,     StopHdl);
signal  (   SIGBREAK,   StopHdl);  ??

And what can I assign nSig to? How does the program 'know' that 'ctrl-c' ??

My program starts a function and I want to be able to cansel it with 'ctrl-c'.

Thanks!
0
jkrCommented:
>>Where should I put     
>>signal  (   SIGINT,     StopHdl);
>>signal  (   SIGBREAK,   StopHdl);  ??

Put these statements into the startup code of your program (e.g. 'InitInstance()' if BC++ uses that or just in 'WinMain()')

You can safely ignore the 'nSig' argument...

The program 'knows' that it was CTRL+C as the handler is assigned to that...

0
bert1Author Commented:
My program does not respond to 'ctrl-c'. I have done exactly what you said. :-(

I there an other way to solve it on?
0
hsk0Commented:
"programming in windows"
If that's Win32, there's an easy solution:

SetConsoleCtrlHandler()

Set the API reference for details.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.