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

标签 c linux bgi

我正在尝试编译以下代码,但它给了我一条错误消息,如下所示。我是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/

相关文章:

linux - 如何在调试(-x)时显示Shell(/bin/sh)脚本中的行号?

linux - 有没有办法查看特定进程的堆栈?

c++ - Turbo C 中的 SVGA 编程

c - 为什么我可以在 c 中的 float 2d 数组中为未分配的内存分配一个值?

通过引用调用一个变量,该变量在不使用全局变量的情况下被另一个函数通过引用调用

c - 为什么这两个相同的功能不同?

C 结构体问题

linux - Bash/Linux 使用自定义字段分隔符按第 3 列排序

c - 计算机图形学中的 BGI

c++ - C++中的多重定义错误