我在使用 union 时犯了一个错误,我不知道为什么。问题出在goto_xy();
我从书中读到的函数中,但无法编译。在此函数中,我试图定位光标,但未REGS
声明变量。我想知道它的功能是什么。
#include<stdio.h>
#include<windows.h>
#include<dos.h>
#include<conio.h>
void goto_xy(int x,int y); //goto is a key word;define the subfunction to creat the original cursor int the coordinate system
void rectangle_clear(int x1,int x2,int y1,int y2); //define the rectangle_clear opening subfunction
void center_clear(int x1,int x2,int y1,int y2); //define the center_clear opening subfunction
void creat(); //define the subfunction of creating the star
int main() //the main function
{
creat();
getch();
center_clear(0,25,0,79);
getch();
}
void center_clear(int x1,int x2,int y1,int y2) //the subfunction which creats the stars while opening the project
{
int x00,y00,x0,y0,i,d;
if((y2-y1)>(x2-x1))
{
d=(x2-x1)/2;
x0=(x1+x2)/2;
y0=y1+d;
y00=y2-d;
for(i=0;i<(d+1);i++)
{
rectangle_clear((x0-i),(x00+i),(y0-i),(y00+i));
}
delay(10); //to delay the dismis of the star
}
else
{
d=(y2-y1)/2;
y0=(y1+y2)/2;
x0=x1+d;
x00=x2-d;
for(i=0;i<d+1;i++)
{
rectangle_clear((x0-i),(x00+i),(y0-i),(y00+i));
}
delay(10);
}
}
void rectangle_clear(int x1,int x2,int y1,int y2) //to creat the star int the shape of a rectangle
{
int i,j;
for(i=y1;i<y2;i++)
{
goto_xy(x1,i);
putchar(' ');
goto_xy(x2,i);
putchar(' ');
delay(10);
}
for(j=x1;j<x2;j++)
{
goto_xy(i,y1);
putchar(' ');
goto_xy(i,y2);
putchar(' ');
delay(10);
}
}
void goto_xy(int x,int y)
{
union REGS r;
r.h.ah=2;
r.h.dl=y;
r.h.dh=x;
r.h.bh=0;
int86(0x10,&r,&r);
}
void creat()
{
int i,j;
for(i=0;i<24;i++)
{
for(j=0;j<79;j++)
{
goto_xy(i,j);
printf("a");
}
}
}