2011-09-29 4 views
1

나는 다음과 같은 코드가 있습니다C 그래픽 라이브러리 오류

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

코드는 선을 만들기 위해 주로이다. 나는 C 경로에 약간의 lib 디렉토리를 추가해야 그 의미를

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.

입니다 : 내가 내 콘솔에서 오류 메시지가이 프로그램을 실행할 때와 같은 (우분투 10.04 버전을 사용하고 있습니다)?

미리 감사드립니다.

답변

5

conio.hgraphics.h은 내가 생각하는 볼랜드 환경에서 나온 고대의 비표준 인터페이스입니다.

+0

우분투 환경에서 나는 C를 설치하지 않았지만 오류없이 다른 C 프로그램을 실행할 수 있지만이 경우에는 할 수 없다 :/ –

+2

이 프로그램은 MS-DOS 환경 용으로 작성되었을 것이므로 결코 컴파일하지 않을 것입니다 표준 리눅스 배포판에서. –

4

이 두 헤더는 Windows 전용입니다. getch()의 경우 에뮬레이트 할 수 있으며 (here 참조) graphics.h의 경우 libgraph을 설치할 수 있습니다.

1

우분투 사용자의 경우 실수는 해당 라이브러리가없는 것입니다. 그래서 우리는 해당 도서관을 포함합니다. 터미널에서 다음 명령을 입력

sudo apt-get install libncurses5-dev libncursesw5-dev 
0

변경이로

dx=abs(x1-x2); 

: OPENGL를 사용하고 conio.h, graphics.h, getch(), closegraph()을 포함하는 줄을 삭제하는

dx=abs(x2-x1); 
-1

시도. 그것들은 Turbo C DOS 컴파일러에서 사용되며 쓸모가 없습니다.

관련 문제