graphics.h not working in code blocks with MinGW in windows 7 64bit
Asked Answered
H

1

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?

Heterogeneity answered 19/1, 2017 at 11:34 Comment(1)
#20314034Offenseless
C
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.

Carswell answered 19/1, 2017 at 11:46 Comment(8)
How are there still tutorials recommending use of this!?Pterodactyl
@Colin__s: Because the internet never forgets?Pringle
@Pringle That doesn't explain why, because this library went obsolete even before internet became mainstream :)Carswell
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.Carswell
But I want to make programs on c++ using graphics library and using TurboC using DOSBOX is very complicated and ugly.Heterogeneity
@Heterogeneity 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.Carswell
University syllabus force me to use Borland BGI. I already have freeglut working in code blocks.Heterogeneity
@Heterogeneity 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.Carswell

© 2022 - 2024 — McMap. All rights reserved.