C 图形库错误

发布于 2024-12-07 08:54:18 字数 1222 浏览 1 评论 0原文

我有以下代码:

#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 编译终止。 test.c:2:致命错误:graphics.h:没有这样的文件或目录 编译终止。

这是否意味着我必须向 C 路径添加一些库?

提前致谢。

I have the following code :

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

The code is mainly for creating a line. But when I run this program I get error message in my console(I'm using Ubuntu 10.04 version) as :

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.

Is that mean I have to add some lib to C path?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

黒涩兲箜 2024-12-14 08:54:19

这两个标头仅适用于 Windows。对于 getch() 您可以模拟它(请参阅此处),对于graphics.h,您可以安装libgraph

Those two headers are Windows-only. For getch() you can emulate it (see here) and for graphics.h you can install libgraph.

╰◇生如夏花灿烂 2024-12-14 08:54:19

对于 Ubuntu 用户来说,错误在于我们没有该库。所以我们包含一个相应的库。在终端中输入以下命令:

sudo apt-get install libncurses5-dev libncursesw5-dev

For Ubuntu users the mistake is when we dont have that library. So we include a corresponding library. Type the following command in terminal:

sudo apt-get install libncurses5-dev libncursesw5-dev
人间☆小暴躁 2024-12-14 08:54:19

改变

dx=abs(x1-x2);

这样:

dx=abs(x2-x1);

change

dx=abs(x1-x2);

by this:

dx=abs(x2-x1);
只等公子 2024-12-14 08:54:19

尝试使用 OPENGL 并删除包含 conio.h,graphics.h,getch(),< 的行代码>closegraph()。这些由 Turbo C DOS 编译器使用并且已过时。

try to use OPENGL and delete the line including conio.h,graphics.h,getch(),closegraph(). Those are used by Turbo C DOS compiler and are obsolete.

是你 2024-12-14 08:54:18

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

conio.h and graphics.h are ancient, non-standard interfaces that came from Borland environments I suppose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文