Click here to Skip to main content
14,937,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just started to study graphics. Since graphics.h is not included in codeblocks i made the required changes and made the below program. But i am getting warning: Deprecated conversion from string constant to char*

int main()
   int gd=0,gm;

What I have tried:

I added the graphics.h and winbgim header filer in include folder. Added libbgi.a in lib folder. Added the path of this library file and "-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32" in linker settings.

Please let me know if i am missing any step here.
Updated 23-Aug-20 18:38pm
Richard MacCutchan 8-Aug-18 6:50am
You did not explain where that error message occurs, and I cannot see any references to strings or char* in the sample code.

You would be better switching to Visual Studio and using the more modern fully supported graphics of Windows GDI/GDI+.
Member 13922884 8-Aug-18 6:55am
My apologies.The error message is displayed for initgraph ().

Pass NULL instead of an empty string. The reason you got this warning (it is a warning and not an error) is that you pass a string literal which is const by definition but the function parameter is not const (char *).

Note also that initgraph() and the other graphic functions belonged to the ancient Turbo-C/C++ compilers for MS-DOS. Using those nowadays via WinBGIm is not the best choice to learn graphics programming.
Member 13922884 8-Aug-18 8:53am
Thanks. But it is also not working. Should i make all the changes again?
Jochen Arndt 8-Aug-18 9:27am
Please define "not working".
Any compiler or linker errors?
If nothing happens during runtime, add error checks to your code inspecting the value of gd and/or using graphresult.

But again:
It is an ancient interface designed for MS-DOS. Think about using other interfaces instead of investing time to learn it and get it running on the shell of recent operating systems.
Member 13922884 8-Aug-18 9:39am
Same warning as before.
Jochen Arndt 8-Aug-18 9:43am
It is a warning and not an error. When not having enabled to treat warnings as errors, an executable file should be created.

However, it should not happen when using

Depending on the compiler you should also get another warning that main() is not returning a value.
Member 13922884 8-Aug-18 11:16am
It is not giving warning now. But i am not getting the output and getting the run time error.
"Visual Studio Just-In-Time Debugger

An unhandled win32 exception occurred in Test1.exe [3992].
Just-In-Time debugging this exception failed with the following error:
No Installed debugger has Just-In-Time debugging enabled. In Visual

Check the documentation index for 'Just-in-time debugging, errors' for
more information."
Jochen Arndt 8-Aug-18 11:34am
Have you changed your code meanwhile to check if the called functions report no errors?

But again: That graphics interface is ancient and has been adopted by the WinBGIm project. Making that running might require some additional work which is far out of beginners scope.

It might be even not possible to use it on recent Windows versions due to the changed shell. Note that even the WinBGIm project is dated from 2005 while the graphics interface originates from 1980's.

BTW: Have you copied the driver files to the directory of your executable?
If not, initgraph() fails which can be detected by checking for success using the gm and gd variables and graphresult.

Member 13922884 8-Aug-18 11:58am
I made no changes to the program except adding NULL in initgraph().
I also added the path of the include folder in the "search directories" option in the project build option.

I understand that WinBGim is quite old. Since i am new to the programming i found this only on the internet hence started to work on it.
Jochen Arndt 8-Aug-18 12:16pm
So initgraph() may have failed and you did not checked it in your code. As a result, the behaviour of your running application is undefined which usually lets the application crash or terminate with an access violation like in your case.

When functions provide some kind of status / error, check that in your code!
Read the documentation of the function. It explains how to check for errors and what the different error codes mean. It explains also that you have to place the driver files in the directory of the executable program when passing an empty or NULL path.

But again: It might be even not possible to use it with recent OS versions.
Member 13922884 8-Aug-18 17:56pm
should i download Dev c++. Are there any issues with this IDE?
Jochen Arndt 9-Aug-18 4:28am
The IDE is not related in any way to your problems.

It is related to using a library that might not work on your platform, not checking if called functions report errors, and probably (you have not confirmed this) not having the BGI driver files in the directory of your executable.

Did you read the documentation?
Here it is:
It contains example code that include the error checks.
Member 13922884 10-Aug-18 3:40am
Thank you. It was an issue of library only. Resolved now. Thanks again.
I followed and I was able to use graphics.h in codeblocks. I hope this will resolve your problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900