如何解决Linux Graphics C程序中的以下错误? [英] How do I solve the following error in Linux Graphics C program?

查看:49
本文介绍了如何解决Linux Graphics C程序中的以下错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to compile the following code,but it gives me a error message as listed below. I am a beginner in linux c graphics and cannot figure it out. Can anyone suggest a solution?

代码:

#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中执行图形代码时,发现了此错误.我进行了很多搜索,但是没有找到满意的答案.终于,我读了很多次错误",发现了第一行错误.

I found this error, when I was doing graphics code in c on ubuntu 18.04. I searched a lot but there was no satisfactory answer for this Issue. finally I read this Error so many time and found some this first line of error.

"[xcb]处理队列时序列号未知".

"[xcb] Unknown sequence number while processing queue" .

错误代码

#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;
}

成功执行后,我得到了所需的输出

After successful execution i got my desired output

这篇关于如何解决Linux Graphics C程序中的以下错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆