可以运行,但出不来结果,想要做数字雨
#include<stdio.h>#include<windows.h>
#include<stdlib.h>
#include<time.h>
#define M 40//行
#define N 100//列
#define TIME 40//刷新的速度,这里是停顿的时间
#define midu 8//密度
//void Pos(int x, int y);//设置光标位置,决定要在什么位置输出
char output[M*N+M+1];//行*列+M个换行+1个结束符
void Create(char rain[M][N]);
void Updata(char rain[M][N]);
void Print(char rain[M][N]);
int main(void)
{
char rain[M][N];
//int changdu;
srand((unsigned)time(NULL));
system("color 0A");
Create(rain);
while(1)
{
Sleep(TIME);
Updata(rain);
}
return 0;
}
void Create(char rain[M][N])
{
int changdu;
int i,j,t;
changdu=rand()%(M/4);
for(i = 0;i < M;++i)
{
for(j = 0;j < N;++j)
{
if(rand()%10 < midu)
rain[i][j] = ' ';
else
rain[i][j] = rand()%10 + '0';
for(t=1;t<=changdu;t++)
{
rain[i-t][j]= rand()%10 + '0';
}
}
}
}
void Updata(char rain[M][N])
{
int i,j,t;
int changdu;
for(i = M-2;i >= 0;--i)
{
for(j = 0;j < N;++j)
{
rain[i+1][j] = rain[i][j];
}
}
for(i = 0;i < N;++i)
{
if(rand()%10 < midu)
rain[0][i] = ' ';
else
rain[0][i] = rand()%10 + '0';
}
Pos(0,0);
Print(rain);
}
void Print(char rain[M][N])
{
int i,j;
int t = 0;
for(i = 0;i < M;++i)
{
for(j = 0;j < N;++j)
{
putchar(rain[i][j]);
}
putchar('\n');
}
putchar('\0');
}
void Pos(int x,int y)
{
HANDLE hOutput;
pos.X = x;
pos.Y = y;
hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOutput,pos);
}