byebye.c 753 B

12345678910111213141516171819202122232425262728293031323334
  1. /* byebye.c -- atexit() example */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. void sign_off(void);
  5. void too_bad(void);
  6. int main(void)
  7. {
  8. int n;
  9. atexit(sign_off); /* register the sign_off() function */
  10. puts("Enter an integer:");
  11. if (scanf("%d",&n) != 1)
  12. {
  13. puts("That's no integer!");
  14. atexit(too_bad); /* register the too_bad() function */
  15. exit(EXIT_FAILURE);
  16. }
  17. printf("%d is %s.\n", n, (n % 2 == 0)? "even" : "odd");
  18. return 0;
  19. }
  20. void sign_off(void)
  21. {
  22. puts("Thus terminates another magnificent program from");
  23. puts("SeeSaw Software!");
  24. }
  25. void too_bad(void)
  26. {
  27. puts("SeeSaw Software extends its heartfelt condolences");
  28. puts("to you upon the failure of your program.");
  29. }