title: Bresenham's line drawing Code
body: <p>I'm trying to draw a line in C language using Bresenham's algorithm.I'm using turbo C++ in dosbox for windows 7 to implement this code.While compiling i'm not getting any error but when i run the code the programs terminates after obtaining the 2 co-ordinates.Please Help..</p>
  
  <p>the message on compiling is as follows..
  <img src="https://i.stack.imgur.com/0bFul.png" alt="enter image description here"></p>
  
  <p>the directories path is as follows<img src="https://i.stack.imgur.com/nxfJS.png" alt="enter image description here"></p>
  
  <p>My code..</p>
  
  <pre><code>  # include &lt;stdio.h&gt;
    # include &lt;conio.h&gt;
    # include &lt;graphics.h&gt;
  
    void main()
    {
      int dx,dy,x,y,p,x1,y1,x2,y2;
      int gd,gm;
  
      clrscr();
  
      printf("\n\n\tEnter the co-ordinates of first point : ");
      scanf("%d %d",&amp;x1,&amp;y1);
      printf("\n\n\tEnter the co-ordinates of second point : ");
      scanf("%d %d",&amp;x2,&amp;y2);
  
      dx = (x2 - x1);
      dy = (y2 - y1);
  
      p = 2 * (dy) - (dx);
  
      x = x1;
      y = y1;
  
      detectgraph(&amp;gd,&amp;gm);
      initgraph(&amp;gd,&amp;gm,"e:\\tc\\bgi");
      putpixel(x,y,WHITE);
  
      while(x &lt;= x2)
      {
        if(p &lt; 0)
        {
          x=x+1;
          y=y;
          p = p + 2 * (dy);
        }
        else
        {
          x=x+1;
          y=y+1;
          p = p + 2 * (dy - dx);
       }
       putpixel(x,y,WHITE);
     }
     getch();
     closegraph();
  }
  </code></pre>