C 如何让边界的另一边打印?

C 如何让边界的另一边打印?,c,extended-ascii,C,Extended Ascii,我有一个c程序,它使用扩展的ascii,根据您输入的两个参数打印出一个框,一个是宽度,另一个是高度 目前,我可以让我的盒子看起来像: ╔══════════╗ ║ ║ ║ ║ ║ ║ ║ ║ ╚══════════╝ 但我不知道如何处理方框边框的右侧。我所拥有的如下: 框_ascii.h 创建动态对话框 我把所有的东西都写了,除了右边的印刷体和左边的印刷体是一样的,但我错了。我所做的每件事都在底部边框下印有右侧边框 我的目标是最终允许您传入第三个参数,以允许您说创建顶部、底部、右侧而不是左侧。

我有一个c程序,它使用扩展的ascii,根据您输入的两个参数打印出一个框,一个是宽度,另一个是高度

目前,我可以让我的盒子看起来像:

╔══════════╗
║
║
║
║
║
║
║
║
╚══════════╝
但我不知道如何处理方框边框的右侧。我所拥有的如下:

框_ascii.h

创建动态对话框

我把所有的东西都写了,除了右边的印刷体和左边的印刷体是一样的,但我错了。我所做的每件事都在底部边框下印有右侧边框

我的目标是最终允许您传入第三个参数,以允许您说创建顶部、底部、右侧而不是左侧。因此,我试图将每一个边框作为一个函数来处理


非常感谢您的帮助。

我认为您应该同时处理左右两边。。。 打印左边框,填充空格,直到到达右边框,然后再打印

如果需要省略两个边框中的任何一个,只需打印空格而不是所选的ASCII字符


我相信你也可以对上下边框采用相同的方法,但在这种情况下,它也可以像你那样正常工作

提示:你必须同时打印两面。迂腐的注释,但没有扩展ASCII,除此之外,还有许多不同的8位字符集,它们的前半部分使用ASCII。因为你要回显的实际上是Unicode代码点,所以这个术语在这里完全不相关。你不能在普通C中的某个位置打印,你还必须打印中间的空格。要打印“at”,可以使用依赖于操作系统的函数,也可以查看ncurses。
#ifndef __box_ascii_h__
#define __box_ascii_h__

// Might not be exact Extended Ascii Characters but they come from:
// https://en.wikipedia.org/wiki/Box-drawing_character#Unicode

#define BOX_TOP_LEFT_CORNER         "\u2554" // ╔
#define BOX_TOP_RIGHT_CORNER        "\u2557" // ╗
#define BOX_BOTTOM_LEFT_CORNER      "\u255A" // ╚
#define BOX_BOTTOM_RIGHT_CORNER     "\u255D" // ╝
#define BOX_SIDE                    "\u2551" // ║
#define BOX_TOP_BOTTOM              "\u2550" // ═

#endif
#include <stdio.h>
#include <stdlib.h>
#include "box_ascii.h"

void print_border(int width, int height);
void print_top_border(int row, int col, int width, int height);
void print_left_side_border(int row, int width);
void print_bottom_border(int row, int col, int width, int height);

// Main App.
int main(int argc, char *argv[]) {
    if(argc < 3) {
        printf("Mustenter width and height.\n");
        return -1;
    }

    // Print the actual border.
    print_border(atoi(argv[1]), atoi(argv[2]));

    return 0;
}

// We want to print the actual box border.
void print_border(int width, int height) {
    int row = 0;
    int col = 0;

    print_top_border(row, col, width, height);
    print_left_side_border(row, width);
    print_bottom_border(row, col, width, height);
}

// This is the top part of the border.
void print_top_border(int row, int col, int width, int height) {
    for(row = 0; row < width; row ++) {
        for(col = 0; col < height; col++) {
            if(row == 0 && col == 0) {
                printf("%s", BOX_TOP_LEFT_CORNER);
            }

            if(row == 0 && col < height) {
                printf("%s", BOX_TOP_BOTTOM);
            }

            if(row == 0 && col == height - 1) {
                printf("%s\n", BOX_TOP_RIGHT_CORNER);
            }
        }
    }
}

// Print the left side of the border.
void print_left_side_border(int row, int width) {
    for(row = 0; row < width; row ++) {
        if(row < width -2) {
            printf("%s\n", BOX_SIDE);
        }
    }
}

// This is the bottom part of the border.
void print_bottom_border(int row, int col, int width, int height) {
    for(row = 0; row < width; row ++) {
        for(col = 0; col < height; col++) {
            if(row == width - 1 && col == 0) {
                printf("%s", BOX_BOTTOM_LEFT_CORNER);
            }

            if(row == width - 1 && col < height) {
                printf("%s", BOX_TOP_BOTTOM);
            }

            if(row == width - 1 && col == height - 1) {
                printf("%s\n", BOX_BOTTOM_RIGHT_CORNER);
            }
        }
    }
}