gpt4 book ai didi

c - 自定义drawRect()函数中是否存在错误或我的错误?

转载 作者:行者123 更新时间:2023-11-30 14:28:02 25 4
gpt4 key购买 nike

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

我正在尝试创建一个在顶部屏幕上显示矩形的函数。如果程序员输入“drawRect(3,3)”,则会创建一个 3 x 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);
}

最佳答案

在循环中,您应该增加 widthloopheightloop,而不是 widthheight。另外,widthloopheightloop 应初始化为 0。

关于c - 自定义drawRect()函数中是否存在错误或我的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6897864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com