簡體   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