0
#include <graphics.h>
#include <bits/stdc++.h>

using namespace std;

void bresen(int x0, int y0, int x1, int y1)
{
    int dx, dy, p, x, y;
    dx=x1-x0;
    dy=y1-y0;
    x=x0;
    y=y0;
    p=2*dy-dx;
    while(x<x1)
    {
        if(p>=0)
        {
            putpixel(x,y,BLUE);
            y=y+1;
            p=p+2*dy-2*dx;
        }
        else
        {
            putpixel(x,y,BLUE);
            p=p+2*dy;
        }
        x=x+1;
    }
}

int main()
{
    int gdriver=DETECT, gmode, x0, y0, x1, 
    initgraph(&gdriver, &gmode,"");
    bresen(100,100,200,200);
    getch();
    closegraph();
    return 0;
}

Here is the screenshot of output screen. I also tried to copy the path of the library folder in initgraph but that is also not working. It is not showing any error on compilation.

output_screen_screenshot

Botje
  • 15,729
  • 2
  • 22
  • 32
  • Does this answer your question? [CodeBlocks error in graphics library](https://stackoverflow.com/questions/25563396/codeblocks-error-in-graphics-library) – Klaycon Aug 25 '20 at 18:22
  • There are numerous results for `codeblocks graphics.h error 0xC0000005` on google. What I gather from these results is that WinBGIm is horribly outdated and unsupported and you should stop trying to use it immediately in favor of something like SDL. It is possible to fix and recompile the broken header if you really, really insist. – Klaycon Aug 25 '20 at 18:23
  • 1
    Graphics.h is the header for a very, very old library, BGI. It can be extremely hard to get those libraries (often written for the 40-year-old DOS or 20-year-old Windows XP operating systems) working on a modern computer using a modern operating system even if you get success compiling. BGI is best avoided if you can. If you can't, [use SDL-BGI](http://libxbgi.sourceforge.net/) which implements the old BGI over top of SDL's graphics library. SDL supports modern hardware and software very well. – user4581301 Aug 25 '20 at 18:24
  • What C++ reference says to use the header ``? Or where did you learn to use it? I'm really curious because it is not standard and a lot of people are using it. – Thomas Matthews Aug 25 '20 at 18:25
  • @ThomasMatthews That would be *C++ For Programmers Who Don't Really Give a *. – user4581301 Aug 25 '20 at 18:27
  • Anyway, Shiva, it's entirely possible you did everything right and this code will never work because the library you're using just doesn't work on your PC. – user4581301 Aug 25 '20 at 18:29
  • There is no guarantee any of this works for a modern computer. If you want to learn graphics, spend time on using what is relevant for today, not a system that is 30+ years old, and hasn't been updated in probably over 10 years. Even if you got this program to work, you cannot use it to forward your learning -- it's old and outdated. – PaulMcKenzie Aug 25 '20 at 18:37
  • [Why should I not #include ?](https://stackoverflow.com/q/31816095/5910058) – Jesper Juhl Aug 25 '20 at 18:46
  • [Why is "using namespace std;" considered bad practice?](https://stackoverflow.com/q/1452721/5910058) – Jesper Juhl Aug 25 '20 at 18:47
  • If this is for a class, do what you need to do to pass, but also politely question why you are being taught to use ancient technology in a fast-paced, ever-changing field. It is probably too late to save you, but you may be able to help the students who follow. – user4581301 Aug 25 '20 at 18:52

0 Answers0