Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h> /* for strlen() */
- #define NAME "GIGATHINK, INC."
- #define ADDRESS "101 Megabuck Plaza"
- #define PLACE "Megapolis, CA 94904"
- #define WIDTH 40
- #define SPACE ' '
- void show_n_char(char ch, int num);
- void center_string(char str[], int width);
- int main(void)
- {
- show_n_char('*', WIDTH);
- putchar('\n');
- center_string(NAME, WIDTH);
- putchar('\n');
- center_string(ADDRESS, WIDTH);
- putchar('\n');
- center_string(PLACE, WIDTH);
- putchar('\n');
- show_n_char('*', WIDTH);
- putchar('\n');
- return 0;
- }
- void show_n_char(char ch, int num)
- {
- int count;
- for (count = 0; count < num; count++)
- putchar(ch);
- }
- void center_string(char str[], int width)
- {
- int count, spaces = (width - strlen(str))/2;
- show_n_char(SPACE,spaces);
- count = 0;
- while (str[count] != '\0')
- putchar(str[count++]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement