【发布时间】:2021-03-30 13:26:07
【问题描述】:
我正在使用 ascii 创建带有输出的数字时钟,并且我制作了一个由五行组成的大量数字。我想使用 gotoxy 移动数字,但只有第一行移动,其余行忽略 y 坐标。
当我的 printf 有换行符时,如何使用 gotoxy 移动我的整个号码?
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include<conio.h>
void gotoxy(int col, int row);
void disp0();
int count=219;
int main()
{
gotoxy(10,10);disp0();
}
void gotoxy(int col, int row)
{
COORD coord;
coord.X = col; coord.Y = row;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void disp0(){
printf("%c%c%c\n%c %c\n%c %c\n%c %c\n%c%c%c",count,count,count,count,count,count,count,count,count,count,count,count);//0
}
这是我得到的输出:
【问题讨论】:
-
Edit 并显示您的代码而不是描述它
-
你在使用 Turbo C 吗?
-
请不要发布您的代码图片,而是将您的代码发布为格式正确的文本
-
我正在使用 devc++ 作为我的编译器
-
当您打印
\n时,光标将位于屏幕最左侧的另一行,这是预期的行为。因此,不要天真地打印\n,而应该再次使用gotoxy将光标定位在正确的位置。