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();
}
该代码主要用于创建一行。但是当我运行这个程序时,我在控制台中收到错误消息(我使用的是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这两个标头仅适用于 Windows。对于
getch()
您可以模拟它(请参阅此处),对于graphics.h
,您可以安装libgraph。Those two headers are Windows-only. For
getch()
you can emulate it (see here) and forgraphics.h
you can install libgraph.对于 Ubuntu 用户来说,错误在于我们没有该库。所以我们包含一个相应的库。在终端中输入以下命令:
For Ubuntu users the mistake is when we dont have that library. So we include a corresponding library. Type the following command in terminal:
改变
这样:
change
by this:
尝试使用 OPENGL 并删除包含
conio.h
,graphics.h
,getch()
,< 的行代码>closegraph()。这些由 Turbo C DOS 编译器使用并且已过时。try to use
OPENGL
and delete the line includingconio.h
,graphics.h
,getch()
,closegraph()
. Those are used by Turbo C DOS compiler and are obsolete.conio.h
和graphics.h
是古老的非标准接口,我认为它们来自 Borland 环境。conio.h
andgraphics.h
are ancient, non-standard interfaces that came from Borland environments I suppose.