5

I had setup the graphics file necessary for the execution of the graphics code in CodeBlocks from the following sites:-

http://www.codewithc.com/how-to-include-graphics-h-in-codeblocks

then I tried this sample code.

#include <graphics.h>
int main( )
{
     initwindow(400, 300, "First Sample");
     circle(100, 50, 40);
     while (!kbhit( ))
     {
         delay(200);
     }
     return 0;
}

but when I Run the code in code blocks I get this

draw.exe has stopped working...

output of the program

Can anyone resolve my problem?

genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

11

This is because graphics.h is Borland's BGI graphics library from 1989, developed for 16 bit MS DOS computers. But you are using a 64 bit Windows computer.

Solution: don't use 28 years old, non-standard libraries.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • 1
    How are there still tutorials recommending use of this!? – Colin Jan 19 '17 at 11:55
  • @Colin__s: Because the internet never forgets? – alk Jan 19 '17 at 11:58
  • 2
    @alk That doesn't explain why, because this library went obsolete even before internet became mainstream :) – Lundin Jan 19 '17 at 12:00
  • 1
    On a more serious note, the Indian school system is probably the major culprit, because they seem to have some central policy about teaching students programming with Borland Turbo. Or at least the vast majority of people asking about Borland Turbo seems to be Indian students. – Lundin Jan 19 '17 at 12:09
  • But I want to make programs on c++ using graphics library and using TurboC using DOSBOX is very complicated and ugly. – Anant_infinity Jan 19 '17 at 13:51
  • 1
    @Anant_infinity Wouldn't you rather use some modern 3D graphics like OpenGL? And then even the raw Windows API for drawing on windows looks far better than Borland BGI. – Lundin Jan 19 '17 at 14:55
  • University syllabus force me to use Borland BGI. I already have freeglut working in code blocks. – Anant_infinity Jan 20 '17 at 10:55
  • 1
    @Anant_infinity Also please note that while Turbo C++ follows the C90 standard somewhat well, it is not even remotely close to following any C++ standard. C++ didn't start to settle down until somewhere around 1995, and it was not standardized before 1998. Which is 8 years after the release of BC++ 3. Therefore, using BC3 to learn C++ is directly harmful and will make you a bad C++ programmer. – Lundin Jan 20 '17 at 12:05