circle.exe Stopped working while using graphics.h in codeblocks - c++

I am using Code::Blocks 16.01 for coding in C++ every code runs properly without showing any problem or error. But ever I runs a graphics program it shows a pop-up window with message circle.exe has stopped working(circle.cpp is the name of my program)(had already copied graphics.h ,winbigim.h and libbgi.a and also corrected the line 302 error in graphics.h and had also had done the linking work).
code that i am using is:-
//circle.cpp
#include <graphics.h>
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
circle(100,100,50);
getch();
closegraph();
return 0;
}
it shows a pop-up window with message circle.exe has stopped working.
But when ever I run the same code in Turbo C++ it runs without any problem/error.
What should I do?

It is because the BGI graphics expect powers that modern systems don't give out willy-nilly anymore.
To use the old library, your options are:
(1) Run your program in DosBox, and x86 emulator
Dos Box
The other option are to get a modern graphics library, like SDL(It's better way and I suggest you).

Related

Program output obtained(no error) but program.exe not working while using graphics.h

I already have graphics.h(and relevant files in MinGW ) but the programs are not working, because after build and run, I get required text output on output window but not the corresponding graphics
because program_name.exe stops working.
I already have searched all over the internet, StackOverflow is my final hope.
I have been doing competitive programming in c+ +, just tried to get into graphics with c++ in code blocks.
#include <graphics.h>
#include <iostream>
using namespace std;
int main()
{ cout<<"a";
int gd= DETECT,gm ;
char driver[] = "";
initgraph(&gd, &gm, driver);
//initgraph(&gd,&gm," ");
circle (100,100,100) ;
getch();
closegraph();
return 0;
}
This is VERY retro. In order for this to even come CLOSE to working you will need to create an MSDOS virtual machine under something like VirtualBox, install DOS 6.2 or similar, install the Borland BGI, Borland C++ 5.02 and then you MIGHT get it to work. Failing that, you could just find an old IBM PC and install DOS on it along with everything else above. Have fun!

Windows error while writing graphic codes in Code Blocks. How to fix it?

I am having trouble using graphics.h in code blocks.
I have installed winbgi.
Edited 302nd line.
Linked lib file and all that stuff is done. So, I don't have any error regarding graphics header file.
But whenever I run/build any code involving graphics functions, windows gives an error ".. has stopped working". How to fix this?
I am using Codeblock v16. Windows 7ultimate - 64bit.
Here is my code:
#include<graphics.h>
int main() {
int gd = DETECT,gm;
initgraph(&gd, &gm, "c:\\tc\\bgi");
line(80, 100, 100, 100);
getch();
//return 0;
}
screenshots:
[SOLVED]
Unfortunately, it was all about 'bad' library files. I think, many have downloaded same(with bug) files in internet. Now I have bug-free files shared in google drive. And also Code::Blocks 16.01 (latest version)
Here's link. Replace old files with these new ones.
I have explained those steps and few FAQs here on this topic with links and test codes.
use of DosBox for emulate MS-DOS in Windows7.
just i can help you with bellow link, its useful.
See : How use of DOSBox in Windows 7

Unable to use graphic programming in codeblock

#include<graphics.h>
#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\TC\\BGI" );
cout<<"Please Enter to continue..."<<endl;
getch();
closegraph();
return 0;
}
All other programmes are running fine on my Codeblock 13.12, but when I run a simple graphic programme compiler crashes giving pop up window that says:
"graphic.exe has stopped working window is checking solution".
It also giving a warning message on compilation:
warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
How to resolve it?It is due to turbo C.
It is due to turbo c.
Turbo c/c++ is ancient and didn't conform any standards. There are no such header files like conio.h or graphics.h for any modern c++ compilers.
Your codeblocks IDE most probably uses the GCC toolchain by default, which doesn't provide these headers.
You should lookup for more modern 3rd party libraries for handling graphics and raw keyboard input (e.g. something like SFML). The c++ standards have no notion about such stuff so far.
For Graphics Programming In C You Need To Install Codeblocks-EP Version. Download From Here http://codeblocks.codecutter.org/setup.exe
Install And Then Go File>New>Project>Winbgim project>GO>>Add Console>>NEXT . Give Project Name,location path And Click Finish. Now Again File >New>Empty File
Write Your C graphics Code>> Build And Run.
This Codeblocks has pre installed built in graphics libraries. So You need not to add anything.

C++: Why does libtiff break the console-output?

So finally I’m not able to help myself out by researching anymore. Hopefully you can help me.
I recently decided to learn C++ in the context of my bachelor-thesis: My first aim is to read the pixel-values of a tiff-image with the libtiff-library. Yet, every call of a function of the library seems to break parts of my program.
Here’s the simple “HelloWorld”-Program, it works as it should:
#include "tiffio.h"
#include <iostream>
using namespace std;
int main() {
cout << "Hello" << endl;
// TIFF* tif = TIFFOpen("path to .tif", "r");
return 0;
}
When I uncomment the second line in main(), the code still does compile without errors (except the warning that ‘tif’ isn’t used) and I can start the program as usual. Yet nothing gets printed into the console anymore. Not “Hello” nor any errors.
Any suggestions where the error could be? The code should be alright, I guess I messed something up during the setup of the library or so. Here’s what I did:
I managed to set up eclipse (Mars, 32bit) for C++ and MinGW (32bit) on my 64bit Win7, then downloaded libtiff 4.0.4 and built it following this instruction.
I created a new C++-project with the mentioned code and did the following adjustments in the project-properties:
Project->Properties->C/C++ General->Paths and Symbols->Library
Paths-> Added “D:/… /tiff-4.0.4/libtiff/.libs”
Project->Properties->C/C++ Build->MinGW C++
Linker->Miscellaneous->Set Linkerflags to “-static-libgcc
-static-libstdc++”
Project->Properties->C/C++ Build->MinGW C++ Linker->Libraries-> Set
(-L) to “D:/… /tiff-4.0.4/libtiff/.libs” and (-l) to “libtiff”
I know the .tif is a valid file as I implemented parts of my program in C#, using the LibTiff.NET library by BitMiracle.
Thank you in advance!
Edit 1: The same error occures, even if TIFF* tif = TIFFOpen("path to .tif", "r"); is never called but written down in a dead part of the code. Debugging does not work either, the program seems to be terminated (exit value 0) before a single line is executed, without any error-reports.
I had the same issue and managed to get rid of it.
I set up eclipse (Mars) for C++ and MinGW on my 64bit Win7, then downloaded libtiff 4.0.4 and built it following this instruction.
After the build, I got two directories containing files:
include
tiff.h
tiffconf.h
tiffio.h
tiffio.hxx
tiffvers.h
lib
libtiff.a
libtiff.dll.a
libtiff.la
libtiffxx.a
libtiffxx.dll.a
libtiffxx.la
I also linked all include files and only the libtiff.a to my project and that solved it, ie, the other lines are now executed.
I hope, I helped with this post.

Codeblocks outputs broken executable

I have downloaded plenty of different versions of code blocks, and none of them compiles quite right. My hello world runs within code blocks just fine. However, when I run the executable outside of codeblocks, it says "Hello.exe has stopped working". There isn't anything wrong with my code (I don't think.) and my mingw compiles fine outside of codeblocks. What does codeblocks do to my executable? Is there some option to fix this? I am on windows 7 64 bit, and my current code blocks version is 10.05. My program:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
cin.ignore();
return 0;
}
I solved the problem. I had a broken compiler (or something like that). My suggestion for other people with this problem is to experiment with different versions of the minGW compiler. Also, change the version of code blocks you are using, or even uninstall everything and restart. The problem with mine was I downloaded a bad compiler. [The truth is, codeblocks isn't the best ide.]