/*从键盘中读取字符 功能:按下普通键时,返回其ASCII码 扫描码CODE=0*/
int INKEY(int *code)
{
int m;
while(!bioskey(1))/*可加入无按键时代码*/;
*code=bioskey(0);
m=*code*255;
if(!m) m=*code>>8;
*code=*code&255;
return m;
}
/*获取机器日期*/
int DATE(char *s,char type)
{
char dat[30];
int num;
strUCt tm *tblock;
time_t t;
t=time(NULL);
tblock=localtime(&t);
strcpy(dt,asctime(tblock));
strcpy(s,"");
switch(type)
{
case 'N':
num=(*tblock).tm_year+1900;
itoa(num,s,10);
break;
case 'Y':
num=(*tblock).tm_mon+1;
itoa(num,s,10);
break;
case 'R':
num=(*tblock).tm_mday;
itoa(num,s,10);
break;
case 'S':
strcpy(dt,asctime(tblock));
MID(s,dt,12,8);
break;
}
}
return num;
}
/*将浮点数转化为字符串*/
/* 参数说明 data:需转换的浮点数;s:输出字符串;len:转换后的长度*/
void f_to_s(double data,char *s,int len)
{
int dec,sign,i;
char *s1,s2[100],s3[100];
s1=0;
s2[0]=0;
s3[0]=0;
s1=fcvt(data,len,&dec,&sign);
if (!sign&&data>=1)
{
MID(s2,s1,dec+1,-1);
MID(s3,s1,1,dec);
strcpy(s,"+");
strcat(s,s3);
strcat(s,".");
strcat(s,s2);
}
if (sign&&fabs(data)>=1)
{
MID(s2,s1,dec+1,-1);
strcpy(s,"-");
MID(s3,s1,1,dec);
strcat(s,s3);
strcat(s,".");
strcat(s,s2);
}
if (!sign&&dec==0)
{
strcpy(s,"+0.");
strcat(s,s1);
}
if (sign&&dec==0)
{
strcpy(s,"-0.");
strcat(s,s1);
}
if (!sign&&dec<0)
{
strcpy(s,"+0.");
for(i=1;i<=fabs(dec);i++)
strcat(s,"0");
strcat(s,s1);
}
if (sign&&dec<0)
{
strcpy(s,"-0.");
for(i=1;i<=fabs(dec);i++)
strcat(s,"0");
strcat(s,s1);
}
if (strlen(s)>len) s[len]=0;
}
/*清除屏幕*/
void CLSXY(int color,int x,int y,int xl,int yl)
{
int x1,y1;
union REGS r;
if(x<1y<1) return;
y--;
x--;
y1=y+yl-1;
x1=x+xl-1;
if (y1>25x1>80)
return;
r.h.ah=6; /*子功能号*/
r.h.al=0; /*滚动行数*/
r.h.ch=y;
r.h.cl=x;
r.h.dh=y1;
r.h.dl=x1;
r.h.bh=color*16;
int86(16,&r,&r);
}
/*显示时间*/
void display_time(int color,int back_color,int y,int x)
{
static char oldtime[9]="";
char newtime[9];
if(y<1x<1) return;
settextstyle(1,0,1);
DATA(newtime,'S');
back_color=7;
if(strcmp(newtime,oldtime))
{
setfillstyle(1,back_color);
setcolor(color);
bar(535,458,635,475);
outtextxy(x,y,newtime);
strcpy(oldtime,newtime);
}
}
/*打印一个矩形*/
void PRINT_KJ(int x,int y,int wide,int high)
{
int i;
for(i=x;i
{
gotoxy(i,y);
cprintf("");
}
gotoxy(x,y+high);
cprintf("");
gotoxy(x+wide,y+high);
cprintf("");
gotoxy(x,y);
cprintf("");
gotoxy(x+wide,y);
cprintf("");
for(i=x+2;i
{
gotoxy(i,y+high);
cprintf("");
}
for(i=y+1;i
{
gotoxy(x,i);
cprintf("");
}
for(i=y+1;i
{
gotoxy(x+wide,i);
cprintf("");
}
}
/*砍掉字符串中所有空格*/
void CUT_ALL_SPC(char *s)
{
int i,n;
char d[10000];
n=0;
for(i=0;i
if(s[i]!=32)
{
d[n]=s[i];
n++;
}
d[n]=0;
strcpy(s,d);
}
/*取子字符串*/
void MID(char *s,char *t,int n,int m)
{
int i,j,p;
if(n<1) n=1;
i=strlen(s);
if(i
if(m<0) m=i;
else m=n+m-1;
if(m>i) m=i;
p=m-n+1;
if(p<0) p=0;
for(i=n-1,j=0;i
t[j]=s[i];
t[p]=0;
}
/*从文件中读取字符*/
int READ_STR(char *s,FILE *fp)
{
int i=0;
if(!fp) return 0;
if(fgets(s,10000,fp)) i=1;
s[strlen(s)-1]=0;
return i;
}
/*字符串左靠齐*/
void MOVE_LEFT(char *d,char *s,int n)
{
int i,l;
l=strlen(s);
if(n>l) n=l;
for(i=0;i
*d++=*s++;
*d=0;
}
/*取左字符串*/
void LEFT(char *d,char *s,int n)
{
int i,l;
i=0;
l=strlen(s);
if(n>l) n=l;
for(i=0;i
d[i]=s[i];
d[n]=0;
}
/*向文件写数据*/
void WR99vE_STR(char *s,FILE *fp)
{
char c=10;
if(!fp) return;
fputs(s,fp);
fputc(c,fp);
}
/*取右字符串*/
void RIGHT(char *dest,char *source,int num)
{
int i,j;
if (num<1) num=0;
num=strlen(source)-num;
if (num<0) num=0;
for(i=0,j=num;j<=strlen(source);i++,j++) dest[i]=source[j];
}
/*打开或关闭光标*/
void CURSOR(int on2off)
{
union REGS r;
if (on2off!=OFF) on2off=10;
r.h.ah=1;
r.h.ch=3;
r.h.cl=on2off;
int86(16,&r,&r);
}
/*喇叭发声*/
void SOUND(int frequency,int time)
{
int i;
i=time*50;
if (i>30000) i=30000;
if (i<50) i=50;
sound(frequency);
MYDELAY(i);
nosound();
}
/*时间延迟*/
void MYDELAY(long t)
{
time_t OldTime;
long t0;
t0=t/55;
if (t0<1) t0=1;
OldTime=clock();
while(clock()-OldTime
}
/*正点报时*/
void