问题描述
嘿伙计们试图像我之前的问题那样制作边框。很抱歉打造一个关于它的全新帖子。
无论如何..我在创建水平线时遇到了麻烦
这个角色只显示在右侧而不是整个东西。
Hey guys im trying to make a border just like on my previous question. Sorry for making a whole new thread about it.
Anyways.. im having trouble creating that horizontal line
the character is only showing on the right side but not the entire thing.
#include <stdio.h>
#include <windows.h>
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;
void gotoXY(int x, int y);
void border();
int main()
{int YEAR;
border();
}
void gotoXY(int x, int y)
{
CursorPosition.X = x; // Locates column
CursorPosition.Y = y; // Locates Row
SetConsoleCursorPosition(console,CursorPosition); // Sets position for next thing to be printed
}
void border()
{
int i;
/*corners*/
gotoXY(7, 3); printf(" %c", 201);
gotoXY(90, 3);printf(" %c", 187);
gotoXY(7, 30); printf(" %c", 200);
gotoXY(90, 30); printf(" %c", 188);
/*vertical lines*/
for(i = 4; i < 30; i++)
{
gotoXY(7, i); printf(" %c", 186);
gotoXY(90, i); printf(" %c", 186);
}
/*horizontal lines */
for (i = 7; i < 90; i++)
{
gotoXY(i, 3); printf(" %c", 205);
gotoXY(i, 30); printf(" %c", 205);
}
}
我的尝试:
What I have tried:
/*horizontal lines */
for (i = 7; i < 90; i++)
{
gotoXY(i, 3); printf(" %c", 205);
gotoXY(i, 30); printf(" %c", 205);
推荐答案
水平部分根本没有显示。
我的意思是它确实只是在gotoXY(x,3/30)而不是整个事情。
the horizontal part isn't showing at all.
I mean it did but only on gotoXY(x, 3/30) and not the entire thing.
从 printf
s中删除空格......:笑:
Remove the space from the printf
s ... :laugh:
gotoXY(i, 3); printf(" %c", 205);
^
|
gotoXY(i, 30); printf(" %c", 205);
^
|
循环中的下一个会立即覆盖你写的字符!
The next one in the loop immediately overwrites the character you wrote!
我看到但对于其他像垂直的那些,我把空间放在它上面它仍然工作正常。我只是觉得你总是要放一个空格,如果它的%c
I see but for the other ones like the vertical ones, i put space on it and it still worked fine. I just thought you always have to put a space if its %c
不,这个空格是一个可打印的角色。
当您使用它来写水平线时,它会覆盖:
Nope, the space is a printable character.
When you use it to write a horizontal line it overwrites:
0123456789 (column number)
| (after gotoXY(0, 1); printf)
| (after gotoXY(1, 1); printf)
! (after gotoXY(2, 1); printf)
...
现在我遇到了程序问题。
正如你可以看到除了if / else语句之外的所有东西都有gotoXY。 />
当我插入gotoXY时,我会收到错误,例如Else is no previous if if
Now i'm having trouble with the program.
As you can see everything has gotoXY besides the one on the if/else statements.
when i insert gotoXY, i get errors such as "Else has no previous if"
那是因为你很懒! :笑:
养成一直使用大括号的习惯:即使是单行如果
或 else
声明:
That's because you are being lazy! :laugh:
Get into the habit of always using curly brackets whenever you possibly can: even for single line if
or else
statements:
if (a == b)
{
statement;
}
else
{
statement;
}
如果你不这样做,那么你最终会这样做:
If you don't, then you end up doing this:
if (a == b)
gotoXY(10,2);
printf("Product:%d", base);
else
statement;
哪个 看起来 是的,但编译器正确地将其视为:
Which looks right, but the compiler rightly sees it as this:
if (a == b)
{
gotoXY(10,2);
}
printf("Product:%d", base);
else
statement;
并抱怨它无法与 else匹配
到如果
它会为你节省大量时间并且让人头疼!
And complains that it can't match the else
to an if
It'll save you a lot of time and head scratching!
这篇关于最后做一个边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!