Hi
I'm running a program that is a continuous loop. I want to dump an array into a text docuemnt when I press ctrl-c to exit. I can already put the arrary into the text doc, I just want to do it when the program exits now.
Thanks
Hi
I'm running a program that is a continuous loop. I want to dump an array into a text docuemnt when I press ctrl-c to exit. I can already put the arrary into the text doc, I just want to do it when the program exits now.
Thanks
man atexit
If you understand what you're doing, you're not learning anything.
I'm not sure about whether Ctrl-C results in "normal program termination." So something like this might also be of interest.Code:#include <stdio.h> #include <signal.h> volatile sig_atomic_t Done = 0; void handler(int code) { Done = 1; } int main(void) { signal(SIGINT, handler); puts("Entering Loop"); while ( !Done ) { /* ... */ } puts("Saving File"); return 0; }
Last edited by Dave_Sinkula; 05-25-2005 at 12:19 PM. Reason: Added 'volatile'.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*