C语言printf控制光标位置和清空屏幕

控制光标位置:

void locateCursor(const int row, const int col){
    printf("%c[%d;%dH",27,row,col);
}

清空屏幕:

void clearScreen(){
    printf("\e[1;1H\e[2J");
}

测试:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void locateCursor(const int row, const int col){
    printf("%c[%d;%dH",27,row,col);
}
void delay(unsigned int xms)  
{
    unsigned int x,y;
    for(x=xms;x>0;x--)
        for(y=1000000;y>0;y--);
}
int main()
{
    int i=0;
    system("clear");
    do{
        locateCursor(1,10);
        printf("%3d%%\n",i);
        delay(10);
        
    }while(i++<100);

}

结果:


猜你喜欢

转载自blog.csdn.net/rong_toa/article/details/80391932
今日推荐