c语言中有关graphics.h中库函数的问题,在线等待,请高手指点!!
我用c实现图形学中生成直线的算法,代码如下:
#include "graphics.h"
#include "stdio.h"
#include "stdlib.h"
main(){
int x0,y0,x1,y1,color,x,y,delta1,delta2,d,a,b;
void midpointline(int x0,int y0,int x1,int y1,int color);
int gdrive=DETECT,gmode;
initgraph(&gdrive,&gmode,"");
setbkcolor(BLUE);
printf("Please input the two point of the line:\n");
scanf("%d,%d,%d,%d",&x0,&y0,&x1,&y1);
printf("Please input color of the line:");
scanf("%d",&color);
cleardevice();
a=y0-y1;
b=x1-x0;
d=2*a+b;
delta1=2*a;
delta2=2*(a+b);
x=x0;
y=y0;
putpixel(x,y,color);
while(x<x1)
{
if(d<0)
{ x++;
y++;
d+=delta2;
}
else
{x++;
d+=delta1;
}
putpixel(x,y,color);
}
getchar();
closegraph();
return;
}
--------------------------------------
编译通过,执行时能输入数据,但图形(即一条直线)没显示,本程序算法应该没问题,是不是调用库函数出错了,请各位高手指教!!