Created
July 10, 2022 09:43
-
-
Save spidey/802226a0a30188c98bd7975336e2e6fd to your computer and use it in GitHub Desktop.
Box print
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <unistd.h> | |
| void ft_putchar(char c); | |
| void box(int rows, int cols); | |
| int main() { | |
| box(10, 20); | |
| return 0; | |
| } | |
| void ft_putchar(char c) { | |
| write(1, &c, 1); | |
| } | |
| void box(int rows, int cols) { | |
| int MAIN_DIAGONAL_CORNER = 0; | |
| int SECONDARY_DIAGONAL_CORNER = 1; | |
| int SIDE_BORDER = 2; | |
| int FILLER = 3; | |
| char glyphs[] = "ACB "; | |
| int x; | |
| int y; | |
| char c; | |
| for (y = 1; y <= rows; ++y) { | |
| for (x = 1; x <= cols; ++x) { | |
| if (y == 1 && x == 1 || y == rows && x == cols) { | |
| c = glyphs[MAIN_DIAGONAL_CORNER]; | |
| } else if (y == 1 && x == cols || y == rows && x == 1) { | |
| c = glyphs[SECONDARY_DIAGONAL_CORNER]; | |
| } else if (y == 1 || y == rows || x == 1 || x == cols) { | |
| c = glyphs[SIDE_BORDER]; | |
| } else { | |
| c = glyphs[FILLER]; | |
| } | |
| ft_putchar(c); | |
| } | |
| ft_putchar('\n'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment