程序小问题,程序运行到后面出错!
void main() {
HANDLE a;
a=GetStdHandle(STD_OUTPUT_HANDLE);
COORD stps[64]={0};
char sText[64]={0};
int Ncount=0;
int Ntime=0;
int Num=0;
srand(time(NULL));
for(int i=0;i<5;i++)
{
sText[i]=rand()%26+'a';
stps[i].X = rand()%80;
Ncount++;
}
while(1)
{
if (Ntime >= 2000)
{
Ntime -= 2000;
sText[Ncount]=rand()%26+'a';
stps[Ncount].X=rand()%80;
stps[Ncount].Y=0;
Ncount++;
}
for (int j=0;j<Ncount;j++)
{
SetConsoleCursorPosition(a,stps[j]);
printf("%c", sText[j]);
}
Num++;
int c=Num/10;
switch(c)
{
case 0 : Sleep(1000);break;
case 1 : Sleep(700);break;
case 2 : Sleep(500);break;
case 3 : Sleep(300);break;
default: Sleep(200);break;
}
Ntime +=700;
for (j=0;j< Ncount;j++)
{
SetConsoleCursorPosition(a,stps[j]);
printf("%c", ' ');
stps[j].Y++;
if (stps[j].Y>24)
{
if (j==Ncount-1)
{
Ncount--;
}
else
{
for (int k=j;k<Ncount-1;k++)
{
sText[k] = sText[k+1];
stps[k].X = stps[k+1].X;
stps[k].Y = stps[k+1].Y;
}
}
}
}
}
}