如何将光标移回C中的第一行? [英] How to move cursor back to the first line in C?

查看:551
本文介绍了如何将光标移回C中的第一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C语言的新手,这是我的代码.

I am new to C and this is my code.

#include<stdio.h>

void printCard(char name, char symbol);

int main()
{
    printCard('J','*');
    printCard('K','&');  
}
void printCard(char name, char symbol)
{
    printf("-------------\n");
    printf("| %c         |\n",name);
    printf("| %c         |\n",symbol);
    printf("|           |\n");
    printf("|           |\n");
    printf("|           |\n");
    printf("|         %c |\n",symbol);
    printf("|         %c |\n",name);
    printf("-------------\n");
}

这是我得到的输出.

是否有办法让第二张卡片出现在第一张卡片的旁边? 谢谢

Is there a way to get that second card to appear beside the first? Thanks

推荐答案

这是对我有用的功能.

void gotoXY(int x, int y)
{

 COORD coord;

 coord.X = x;

 coord.Y = y;

 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

感谢@PCLuddite指向我检查setConsoleCursorPosition,它帮助我在线找到了以上功能.希望这对其他人有帮助.

Thanks @PCLuddite for pointing me to check setConsoleCursorPosition which helped me find this above function online. Hope this helps others.

这篇关于如何将光标移回C中的第一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆