自定义drawRect()函数中是否存在错误?

自定义drawRect()函数中是否存在错误?,c,function,graphics,C,Function,Graphics,我的drawRect()函数的行为就像有bug一样。我正在尝试确定以下内容中是否存在错误,或者,如果没有,我正在错误地做什么 我正在尝试制作一个函数,在顶屏幕上显示一个矩形。如果程序员键入“drawRect(3,3)”,将创建一个3×3的矩形。然而,如果程序员键入“drawRect(3,4)”,矩形的右上角将显示,然后是一个无限长的顶部。有人能帮我吗?这是我的密码: #include <stdio.h> #include <stdlib.h> #define SIDES

我的drawRect()函数的行为就像有bug一样。我正在尝试确定以下内容中是否存在错误,或者,如果没有,我正在错误地做什么

我正在尝试制作一个函数,在顶屏幕上显示一个矩形。如果程序员键入“drawRect(3,3)”,将创建一个3×3的矩形。然而,如果程序员键入“drawRect(3,4)”,矩形的右上角将显示,然后是一个无限长的顶部。有人能帮我吗?这是我的密码:

#include <stdio.h>
#include <stdlib.h>

#define SIDES 0xB3
#define TOP_RIGHT 0xBF
#define BOTTOM_LEFT 0xC0
#define TOP_BOTTOM 0xC4
#define BOTTOM_RIGHT 0xD9
#define TOP_LEFT 0xDA

int heightloop;
int widthloop;

int displayrect(int height, int width)
{
printf("%c",TOP_LEFT);
for(widthloop=1;widthloop<width-2;width++)
{
    printf("%c",TOP_BOTTOM);
}
printf("%c\n",TOP_RIGHT);
for(heightloop=1;heightloop<height-2;height++)
{
    printf("%c",SIDES);
    for(widthloop=1;widthloop<width-2;width++)
    {
        printf(" ");
    }
    printf("%c\n",SIDES);
}

printf("%c",BOTTOM_LEFT);
for(widthloop=1;widthloop<width-2;width++)
{
    printf("%c",TOP_BOTTOM);
}
printf("%c",BOTTOM_RIGHT);
return(0);
}
#包括
#包括
#定义边0xB3
#定义右上角0xBF
#定义左下角0xC0
#定义上下0xC4
#定义右下角0xD9
#定义左上角0xDA
内高度环;
整数循环;
int displayrect(int高度、int宽度)
{
printf(“%c”,左上角);
对于(widthloop=1;widthloop这样的循环:

for(widthloop=1;widthloop<width-2;width++)

用于(widthloop=1;widthloop在你的循环中,你应该增加
widthloop
heightloop
,而不是
widthloop
heightloop
。另外
widthloop
heightloop
应该初始化为0。

谢谢!我想我正在增加矩形的宽度,因此矩形的宽度也应该增加不断增加,就像我遇到的问题一样。
for(heightloop=1;heightloop<height-2;height++)