voco失活剂假货:C语言高手请进来!!!!!!!无限循环问题

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 03:43:10
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <graphics.h>
#define ESC 0x1b
struct PTS {int x, y;}; int GraphDriver;int GraphMode;
double AspectRatio;int MaxX, MaxY;int MaxColors;int ErrorCode;
struct palettetype palette;
void Initialize();
void MainWindow(char *header);
void Pause(void);
void DrawBorder(void);

int main()
{

char c1,b,c2,c3,c4,c5,c6,c7,c8,c9,c0;
Initialize();

c1=201;c2=205;
c3=203;c4=187;
c5=204;c6=206;
c7=185;c8=200;
c9=202;c0=188;
while(!kbhit()) /* 就是这个东西拉*/
{
printf("\t\t\t\t%c%c%c%c%c%c%c%c%c%c\n",c1,c2,c3,c2,c2,c2,c2,c2,c2,c4);
printf("\t\t\t\t%c%c%c%c%c%c%c%c%c%c\n",c5,c2,c6,c2,c2,c2,c2,c2,c2,c7) ;
printf("\t\t\t\t%c%c%c%c%c%c%c%c%c%c\n",c8,c2,c9,c2,c2,c2,c2,c2,c2,c0);
}
Pause();
}

void Initialize(void)
{
int xasp, yasp;
GraphDriver = DETECT;
initgraph( &GraphDriver, &GraphMode, "" );
ErrorCode = graphresult();
if( ErrorCode != grOk )
{printf(" Graphics System Error: %s\n",
grapherrormsg( ErrorCode ) );
exit( 1 );
}
getpalette( &palette );
MaxColors = getmaxcolor() + 1;
MaxX = getmaxx();MaxY = getmaxy();
getaspectratio( &xasp, &yasp );
AspectRatio = (double)xasp / (double)yasp;
}
void Pause(void)
{
int c;
c = getch();
if( ESC == c )
{
closegraph();
exit( 1 );
}
if( 0 == c )
{
c = getch();
}
cleardevice();
}
如上程序,我运行过了,没问题
请问有没人用过上面标注的 while(!kbhit())
这个可以让程序无限的执行下去 ,这里我用自定义函数 Pause来使它停止.
我想问的是 while(!kbhit()) 使程序重复执行的速度 太快了,就是说画面向上升的速度太快了,以致于看不清它的形状,有什么办法可以使得他的速度减慢么???

kbhit()
检测键盘是否有键按下。
如果有键按下,则返回对应键值;否则返回零。
kbhit不等待键盘按键。无论有无按键都会立即返回。
如果要循环变慢
可以在循环里面加一个sleep(要停止的时间 毫秒单位);

while(!kbhit()) /* 就是这个东西拉*/
{
printf("\t\t\t\t%c%c%c%c%c%c%c%c%c%c\n",c1,c2,c3,c2,c2,c2,c2,c2,c2,c4);
printf("\t\t\t\t%c%c%c%c%c%c%c%c%c%c\n",c5,c2,c6,c2,c2,c2,c2,c2,c2,c7) ;
printf("\t\t\t\t%c%c%c%c%c%c%c%c%c%c\n",c8,c2,c9,c2,c2,c2,c2,c2,c2,c0);
}
delay(500);
Pause();
}

kbhit() returns a nonzero value if a key has been pressed. Otherwise, it returns 0.

可以使用delay(int ms),来降低速度,

一般的,使用gettime,进行时序控制,在循环中,加入kbhit() ,
for(;;)
{
t1=gettime()

if(t1-t0<xxx)countine;

t0=t1;

do something.........

if((!kbhit())
{
c=getch();
switch(c)
case....

}
}