gpt4 book ai didi

c - 如何解决 Linux Graphics C 程序中的以下错误?

转载 作者:太空宇宙 更新时间:2023-11-04 10:37:55 25 4
gpt4 key购买 nike

我正在尝试编译以下代码,但它给我一条错误消息,如下所列。我是 linux c 图形的初学者,无法弄清楚。谁能提出解决方案?

代码:

#include<stdio.h>
#include<graphics.h>
void main()
{
int gd = DETECT, gm;
int dx, dy, p, end;
float x1, x2, y1, y2, x, y;
initgraph(&gd, &gm,NULL);
printf("Enter Value of X1: ");
scanf("%f", &x1);
printf("Enter Value of Y1: ");
scanf("%f", &y1);
printf("Enter Value of X2: ");
scanf("%f", &x2);
printf("Enter Value of Y2: ");
scanf("%f", &y2);

dx = abs(x1 - x2);
dy = abs(y1 - y2);

p = 2 * dy - dx;
if(x1 > x2)
{
x = x2;
y = y2;
end = x1;
}
else
{
x = x1;
y = y1;
end = x2;
}
putpixel(x, y, 10);
while(x < end)
{
x = x + 1;
if(p < 0)
{
p = p + 2 * dy;
}
else
{
y = y + 1;
p = p + 2 * (dy - dx);
}
putpixel(x, y, 10);
}
getch();
closegraph();
}

错误信息:

meshramsd@ubuntu:~/libgraph-1.0.2$ ./b
[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.
b: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
[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.
b: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted (core dumped)

最佳答案

我在 ubuntu 18.04 上用 c 编写图形代码时发现了这个错误。我搜索了很多,但这个问题没有令人满意的答案。最后我多次阅读这个错误并发现了一些第一行错误。

[xcb] 处理队列时序列号未知”。

有错误的代码

#include <stdio.h>
#include <graphics.h>

int main() {

int gd = DETECT,gm;

int x1,y1,x2,y2;
float step,dx,dy;

initgraph(&gd,&gm,NULL); // I found Error here Initialized Graph before standard input
printf("enter the value of x1 and y1 : ");
scanf("%d %d",&x1,&y1);
printf("Enter the value of x2 and y2 : ");
scanf("%d %d",&x2,&y2);

dx=abs(x2-x1);
dy=abs(y2-y1);

if (dx >= dy)
step=dx;
else
step=dy;

dx=dx/step;
dy=dy/step;

int x=x1;
int y=y1;

int i=1;
while(i <= step)
{
putpixel(x,y,5);
x=x+dx;
y=y+dy;
i++;
delay(100);
}
getchar();
closegraph();
return 0;
}

无错代码

#include <stdio.h>
#include <graphics.h>

int main() {
int gd = DETECT,gm;

int x1,y1,x2,y2;
float step,dx,dy;


printf("enter the value of x1 and y1 : ");
scanf("%d %d",&x1,&y1);
printf("Enter the value of x2 and y2 : ");
scanf("%d %d",&x2,&y2);

initgraph(&gd,&gm,NULL); //after correction I initialized graph after standard input

dx=abs(x2-x1);
dy=abs(y2-y1);

if (dx >= dy)
step=dx;
else
step=dy;

dx=dx/step;
dy=dy/step;

int x=x1;
int y=y1;

int i=1;
while(i <= step)
{
putpixel(x,y,5);
x=x+dx;
y=y+dy;
i++;
delay(100);
}
getchar();
closegraph();
return 0;
}

成功执行后我得到了我想要的输出 enter image description here

关于c - 如何解决 Linux Graphics C 程序中的以下错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36527249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com