繁体   English   中英

C图形库错误

[英]C Graphics Library Error

我有以下代码:

#include<stdio.h>
#include<conio.h>
#include<math.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,"");
    printf("\nEnter the value of x1: ");
    scanf("%f",&x1);
    printf("\nEnter the value of y1: ");
    scanf("%f",&y1);
    printf("\nEnter the value of x2: ");
    scanf("%f",&x2);
    printf("\nEnter the value of y2: ");
    scanf("%f",&y2);
    dx=abs(x1-x2);
    dy=abs(y2-y1);
    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();
}

该代码主要用于创建一行。 但是,当我运行该程序时,在控制台(我使用的是Ubuntu 10.04版本)中收到错误消息,如下所示:

test.c:2: fatal error: conio.h: No such file or directory compilation terminated. test.c:2: fatal error: graphics.h: No such file or directory compilation terminated.

这是否意味着我必须在C路径中添加一些lib?

提前致谢。

conio.hgraphics.h是我认为来自Borland环境的古老的非标准接口。

这两个标头仅适用于Windows。 对于getch()您可以对其进行仿真(请参见此处 );对于graphics.h ,则可以安装libgraph

对于Ubuntu用户,错误是当我们没有该库时。 因此,我们包括一个相应的库。 在终端中键入以下命令:

sudo apt-get install libncurses5-dev libncursesw5-dev

更改

dx=abs(x1-x2);

这样:

dx=abs(x2-x1);

尝试使用OPENGL并删除包括conio.hgraphics.hgetch()closegraph() Turbo C DOS编译器使用的那些已过时。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM