partb.c 584 B

12345678910111213141516171819202122232425
  1. // partb.c -- rest of the program
  2. // compile with parta.c
  3. #include <stdio.h>
  4. extern int count; // reference declaration, external linkage
  5. static int total = 0; // static definition, internal linkage
  6. void accumulate(int k); // prototype
  7. void accumulate(int k) // k has block scope, no linkage
  8. {
  9. static int subtotal = 0; // static, no linkage
  10. if (k <= 0)
  11. {
  12. printf("loop cycle: %d\n", count);
  13. printf("subtotal: %d; total: %d\n", subtotal, total);
  14. subtotal = 0;
  15. }
  16. else
  17. {
  18. subtotal += k;
  19. total += k;
  20. }
  21. }