我使用C语言中的BGI库编写了生成中点椭圆的代码。编译后,我尝试运行该代码。但是打开以接受输入的窗口立即关闭,甚至没有接受输入。我试图增加延迟时间,但是那也不起作用。从昨天开始就一直试图解决该问题,但未能解决问题。
我的代码:
#include<stdio.h>
#include<graphics.h>
void main()
{
int x1,x2,y1,y2,Xwmin,Ywmin,Xwmax,Ywmax,dx,dy,count,tmin,tmax;
float p[4],q[4];
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
printf("Enter the values of X1 and Y1:");
scanf("%d %d",&x1,&y1);
printf("Enter the values of X2 and Y2:");
scanf("%d %d",&x2,&y2);
printf("Enter the coordinates of the window:\n");
printf("Value of Xwmin:");
scanf("%d",&Xwmin);
printf("Value of Xwmax:");
scanf("%d",&Xwmax);
printf("Value of Ywmin:");
scanf("%d",&Ywmin);
printf("Value of Ywmax:");
scanf("%d",&Ywmax);
rectangle(Xwmin,Ywmax);
dx=x2-x1;
dy=y2-y1;
p[0]=-dx;
p[1]=dx;
p[2]=-dy;
p[3]=dy;
q[0]=x1-Xwmin;
q[1]=Xwmax-x1;
q[2]=y1-Ywmin;
p[3]=Ywmax-y1;
for(count = 0; count < 4; count++)
{
if(p[count] == 0)
{
printf("\nLine is parallel\n");
if(q[count] >= 0)
{
if(count < 2)
{
if(y1 < Ywmin)
{
y1 = Ywmin;
}
if(y2 > Ywmax)
{
y2 = Ywmax;
}
line(x1,y2);
}
if(count > 1)
{
if(x1 < Xwmin)
{
x1 = Xwmin;
}
if(x2 > Xwmax)
{
x2 = Xwmax;
}
line(x1,y2);
}
}
}
}
int t_min=0;
int t_max=1;
for(count =0;count<4;count++)
{
float t = q[count] / p[count];
if(p[count] < 0)
{
if(tmin <= t)
{
tmin = t;
}
}
else
{
if(tmax > t)
{
tmax = t;
}
}
}
if(tmin < tmax)
{
int t_x0 = x1 + tmin * p[1];
int t_x1 = x1 + tmax * p[1];
int t_y0 = y1 + tmin * p[3];
int t_y1 = y1 + tmax * p[3];
line(t_x0,t_y0,t_x1,t_y1);
}
delay(5000);
closegraph;
}
我得到的错误是:
./a.out
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting,sorry about that.
a.out: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted (core dumped)
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting,sorry about that.
a.out: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
我正在Ubuntu 16.04中使用GCC编译器 预先谢谢你。