Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h> /* for strlen() */
  4.  
  5. #define NAME "GIGATHINK, INC."
  6. #define ADDRESS "101 Megabuck Plaza"
  7. #define PLACE "Megapolis, CA 94904"
  8. #define WIDTH 40
  9. #define SPACE ' '
  10.  
  11. void show_n_char(char ch, int num);
  12. void center_string(char str[], int width);
  13.  
  14. int main(void)
  15. {
  16.     show_n_char('*', WIDTH);
  17.     putchar('\n');
  18.  
  19.     center_string(NAME, WIDTH);
  20.     putchar('\n');
  21.  
  22.     center_string(ADDRESS, WIDTH);
  23.     putchar('\n');
  24.  
  25.     center_string(PLACE, WIDTH);
  26.     putchar('\n');
  27.  
  28.     show_n_char('*', WIDTH);
  29.     putchar('\n');
  30.  
  31.     return 0;
  32. }
  33.  
  34. void show_n_char(char ch, int num)
  35. {
  36.     int count;
  37.  
  38.     for (count = 0; count < num; count++)
  39.         putchar(ch);
  40. }
  41.  
  42. void center_string(char str[], int width)
  43. {
  44.     int count, spaces = (width - strlen(str))/2;
  45.  
  46.     show_n_char(SPACE,spaces);
  47.     count = 0;
  48.     while (str[count] != '\0')
  49.         putchar(str[count++]);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement