#include <stdio.h> // Function declarations void draw_top_bottom_border(char corner_char, char horizontal_char, int width); void draw_vertical_sides(char vertical_char, int width, int height); void draw_ascii_box(char horizontal_char, char vertical_char, char corner_char, int width, int height); // Function to draw the top and bottom borders void draw_top_bottom_border(char corner_char, char horizontal_char, int width) { printf("%c", corner_char); for (int i = 0; i < width - 2; i++) { printf("%c", horizontal_char); } printf("%c\n", corner_char); } // Function to draw the vertical sides void draw_vertical_sides(char vertical_char, int width, int height) { for (int i = 0; i < height - 2; i++) { printf("%c", vertical_char); for (int j = 0; j < width - 2; j++) { printf(" "); } printf("%c\n", vertical_char); } } // Function to draw the ASCII box void draw_ascii_box(char horizontal_char, char vertical_char, char corner_char, int width, int height) { // Draw top border draw_top_bottom_border(corner_char, horizontal_char, width); // Draw vertical sides draw_vertical_sides(vertical_char, width, height); // Draw bottom border draw_top_bottom_border(corner_char, horizontal_char, width); } // Main function to get user inputs and test the draw_ascii_box function int main() { char horizontal_char; char vertical_char; char corner_char; int width; int height; // Get user inputs scanf(" %c", &horizontal_char); scanf(" %c", &vertical_char); scanf(" %c", &corner_char); scanf("%d", &width); scanf("%d", &height); // Draw the ASCII box based on user inputs draw_ascii_box(horizontal_char, vertical_char, corner_char, width, height); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter