#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
//#include"device.h"
#define round(a) ((int)(a+0.5))
void main()
{
float x1,y1,x2,y2,dx,dy,x,y;
int l,k,xinc,yinc;
// int gmode,gdrive=DETECT;
//initgraph(&gdrive,&gmode,"c\\tc\\bgi");
clrscr();
printf("enter the co-ordinates");
printf("enter first co-ordinate x & Y");
scanf("%f %f",&x1, &y1);
printf("enter second co-ordinates x & y");
scanf("%f %f",&x2, &y2);
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
{
l=abs(dx);
}
else
{
l=abs(dy);
}
xinc=dx/l;
yinc=dy/l;
x=x1;
y=y1;
k=0;
// putpixel(round(x),round(y),k);
for(k=0;k<l;k++)
{
x+=xinc;
y+=yinc;
putpixel(round(x),round(y),l);
}
getch();
}
views:
52answers:
2
+1
A:
// int gmode,gdrive=DETECT;
//initgraph(&gdrive,&gmode,"c\\tc\\bgi");
You commented the code but that's required to see the results of putpixel(). The initgraph() call didn't work because you forgot the : in the path ("c:\tc\bgi"). Not sure if that fixes all of the problems, this stuff is ancient and support for it is disappearing. If you can't get the video adapter to switch to the DOS graphics mode then you're stuck until you find an old machine.
Hans Passant
2010-07-23 09:26:00
A:
To call graphics functions you must first call initgraph
function. See the documentation for initgraph
function.
To see the error run the executable file from command prompt.
See the example which is copied from Turbo C help:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}
/* draw a line */
line(0, 0, getmaxx(), getmaxy());
/* clean up */
getch();
closegraph();
return 0;
}
chanchal1987
2010-07-23 09:41:16