gpt4 book ai didi

c - 如何在特定位置打印文本?

转载 作者:行者123 更新时间:2023-12-04 12:36:14 25 4
gpt4 key购买 nike

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#define MAX 25

main(){
int a[MAX],i,j,lvl=2,score=0;
float time=1.0,speed;
speed=time/lvl;

clrscr();

for(i=0;i<MAX;i++)
a[i]=rand()%50+1;

while(1){
for(j=0;j<MAX;j++){
gotoxy(a[j],1);
printf("*");
gotoxy(1,1);
insline();
sleep(speed);
score++;
gotoxy(57,1);
clrscr();
printf("%d",score);
if(score==100)
lvl++;
}
}
}

您好,我正在尝试使用 gotoxy() 在屏幕的右上角打印分数。我使用 gotoxy(1,1) 设置了使用 insline() 插入空行的光标位置。但每次我在屏幕上打印乐谱时,它都会连续打印乐谱,如下所示:

DOS screenshot with scores repeating down the right side

强调的文本还有其他方法可以打印分数并在 insline() 插入新行时将其删除到最后一个位置,这样最后一个分数就不会被删除打印在屏幕上但只有当前分数?

最佳答案

你应该使用这个函数

WriteConsoleOutput(....);

在 MSDN 上查看

http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404(v=vs.85).aspx

关于c - 如何在特定位置打印文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14195596/

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