lethead2.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* lethead2.c */
  2. #include <stdio.h>
  3. #include <string.h> /* for strlen() */
  4. #define NAME "GIGATHINK, INC."
  5. #define ADDRESS "101 Megabuck Plaza"
  6. #define PLACE "Megapolis, CA 94904"
  7. #define WIDTH 40
  8. #define SPACE ' '
  9. void show_n_char(char ch, int num);
  10. int main(void)
  11. {
  12. int spaces;
  13. show_n_char('*', WIDTH); /* using constants as arguments */
  14. putchar('\n');
  15. show_n_char(SPACE, 12); /* using constants as arguments */
  16. printf("%s\n", NAME);
  17. spaces = (WIDTH - strlen(ADDRESS)) / 2;
  18. /* Let the program calculate */
  19. /* how many spaces to skip */
  20. show_n_char(SPACE, spaces);/* use a variable as argument */
  21. printf("%s\n", ADDRESS);
  22. show_n_char(SPACE, (WIDTH - strlen(PLACE)) / 2);
  23. /* an expression as argument */
  24. printf("%s\n", PLACE);
  25. show_n_char('*', WIDTH);
  26. putchar('\n');
  27. return 0;
  28. }
  29. /* show_n_char() definition */
  30. void show_n_char(char ch, int num)
  31. {
  32. int count;
  33. for (count = 1; count <= num; count++)
  34. putchar(ch);
  35. }