DIGIT-ARC read-only archive · snapshot: July 23, 2026

Debug the DDA

3 posts · originally from https://geek.digit.in/community/threads/debug-the-dda.85028/

Plasma_Snake
Plasma_Snake Original post #1
Apr 11, 2008 at 9:39 AM
Below the is the program code for DDA line drawing algorithm. It compiles with no error and runs fine on my college computers but at my home it gives "run time error" which is"BGI Error: Graphics not initialized(use 'initgraph')".:( Resolve it please.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd,gm,x1,x2,y1,y2,xinc,yinc,i,dx,dy,len,x,y;
gd = DETECT;
initgraph(&gd,&gm," ");
printf("enter the coordinates of x1,y1 and x2,y2 ");
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
dx = ( x2-x1 );
dy = ( y2-y1 );
if( dx > dy )
len = abs(dx);
else
len = abs(dy);
xinc = dx/len;
yinc = dy/len;
x = x1;
y = y1;
for(i=1;i<=len;i++)
{ x = x+xinc;
y = y+yinc;
putpixel(x,y,3);
}
getch();
}
QwertyManiac
Apr 11, 2008 at 9:57 AM
I don't know BGI etc but shouldn't your gm variable be initialized before address-passing to initgraph() ?
DigitalDude
Apr 11, 2008 at 10:03 AM
*www.thinkdigit.com/forum/showthread.php?t=7038


_