Terminate C++ program by user input

May 14, 2012 at 10:23pm
Hi,

I have written an exe that could run for hours. I want to add feature that if a user wants to terminate the program in a few minutes instead of waiting for hours, he could just press Ctrl-C and a clean-up function gets called, which cleans up heap memory and exits.

How exactly could this be done?

Thanks!
May 14, 2012 at 10:59pm
How do you get user input in your program?
May 14, 2012 at 11:34pm
By command line arguments. The program could run infinitely. But I'd like it to listen to Ctrl-C and if user presses Ctrl-C, then clean-up is called and program exits.
May 15, 2012 at 12:42am
See http://www.yolinux.com/TUTORIALS/C++Signals.html for examples on handling the signal.
Topic archived. No new replies allowed.