Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解决Linux图形C程序中的以下错误?_C_Linux_Graphics - Fatal编程技术网

如何解决Linux图形C程序中的以下错误?

如何解决Linux图形C程序中的以下错误?,c,linux,graphics,C,Linux,Graphics,我试图编译以下代码,但它给我一个错误消息,如下所示。我是LinuxC图形的初学者,无法理解它。有人能提出解决办法吗 代码: 您可以尝试使用libsvga,它似乎在LinuxMint上运行良好——我在Mac上的Virtualbox下运行了Mint,没有任何问题 我安装了以下软件包: sudo apt-get install svgalib-bin libsvga1 libsvga1-dev 然后我把你的代码侵入了以下内容: #include <stdlib.h> #include &

我试图编译以下代码,但它给我一个错误消息,如下所示。我是LinuxC图形的初学者,无法理解它。有人能提出解决办法吗

代码:


您可以尝试使用
libsvga
,它似乎在LinuxMint上运行良好——我在Mac上的Virtualbox下运行了Mint,没有任何问题

我安装了以下软件包:

sudo apt-get install svgalib-bin libsvga1 libsvga1-dev
然后我把你的代码侵入了以下内容:

#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <vga.h>
#include<stdio.h>

void main()
{
   int dx, dy, p, end;

   /* detect the chipset and give up supervisor rights */
   if (vga_init() < 0)
        return EXIT_FAILURE;

   vga_setmode(G1024x768x256);  /* some low resolution dont work */ 
   vga_setcolor(14);         /* color of pixel */

   float x1, x2, y1, y2, x, y;
   x1=10;
   y1=40;
   x2=800;
   y2=500;

   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;
   }
   vga_drawpixel(x, y);
   while(x < end){
      x = x + 1;
      if(p < 0)
      {
         p = p + 2 * dy;
      } else {
         y = y + 1;
         p = p + 2 * (dy - dx);
      }
      vga_drawpixel(x, y);
   }
   sleep(10);

   /* restore textmode and fall back to ordinary text console handling */
   vga_setmode(TEXT);

}
并与:

sudo ./graphics
我得到了这个输出-如果你想要不同的颜色或尺寸,你可以很容易地改变数字


我在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;
}
#包括
#包括
int main(){
int gd=检测,gm;
int-x1,y1,x2,y2;
浮动步长,dx,dy;
initgraph(&gd,&gm,NULL);//在标准输入之前初始化图形时,我在这里发现了错误
printf(“输入x1和y1的值:”);
scanf(“%d%d”、&x1和&y1);
printf(“输入x2和y2的值:”);
扫描频率(“%d%d”、&x2和&y2);
dx=abs(x2-x1);
dy=abs(y2-y1);
如果(dx>=dy)
阶跃=dx;
其他的
阶跃=dy;
dx=dx/步;
dy=dy/步;
int x=x1;
int y=y1;
int i=1;
while(i=dy)
阶跃=dx;
其他的
阶跃=dy;
dx=dx/步;
dy=dy/步;
int x=x1;
int y=y1;
int i=1;

虽然(i graphics.h只是一个头文件。您实际使用的是libgraph。当您指定它时,可能会得到更多答案。如果您试图在图像上画一些线,可以使用Magick++。这些可能会让您开始使用,另一个选项可能是使用
libvga
,请在此处查看我的答案,但此选项也会接受co上的输入。)如果我们想在图形控制台上进行输入,尽管您的回答很有用。
gcc graphics.c -lvga -lm -o graphics
sudo ./graphics
#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;
}