put_put.c 607 B

123456789101112131415161718192021222324252627282930313233
  1. //put_put.c -- user-defined output functions
  2. #include <stdio.h>
  3. void put1(const char *);
  4. int put2(const char *);
  5. int main(void)
  6. {
  7. put1("If I'd as much money");
  8. put1(" as I could spend,\n");
  9. printf("I count %d characters.\n",
  10. put2("I never would cry old chairs to mend."));
  11. return 0;
  12. }
  13. void put1(const char * string)
  14. {
  15. while (*string) /* same as *string != '\0' */
  16. putchar(*string++);
  17. }
  18. int put2(const char * string)
  19. {
  20. int count = 0;
  21. while (*string)
  22. {
  23. putchar(*string++);
  24. count++;
  25. }
  26. putchar('\n');
  27. return(count);
  28. }