控制光标位置:
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); }
结果: