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

FILE *temp_file;
void leave(int sig);

main() 
{
  (void) signal(SIGINT,leave);
 
  temp_file = fopen("/tmp/foo","w");

  for(;;) 
    {
      /* do things... */
      
      printf("Press Enter to loop, or Ctrl-C to interrupt\n");
      (void)getchar();
    }
  
  /* can't get here ... */
   
  exit(0);
}


/* on receipt of SIGINT, close /tmp/foo file */

void leave(int sig) 
{
  printf("See file /tmp/foo");
  fprintf(temp_file,"Interrupted !!!\n");
  fclose(temp_file);
  exit(sig);
}
