1

I tried everything, and I can't even start this simple graph code. I have installed the graphics.h, winbgim.h and libbgi.a in all the right folders. (include and lib). Linkers, too -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

I'm using CodeBlocks 16.01. I have also tried it in Dev-C++ with no luck.

First I got error:

C:\Program Files (x86)\CodeBlocks\MinGW\include\graphics.h|302|error: redefinition of 'int right'

But I solved that by changing the graphics.h file, int right needs to be replaced with int top.

Also there is 1 warning -

C:\Users\Davor\Desktop\New Project\drugi\main.cpp||In function 'int main()':| C:\Users\Davor\Desktop\New Project\drugi\main.cpp|15|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]| ||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

After that, when I press 'Build and run' i get

" *.exe has stopped working. " In the background I first get -

Process returned 255 (0xFF) execution time : 91.666 s Press any key to continue.

But every other time I get -

Process returned -1073741819 (0xC0000005) execution time : 26.494 s Press any key to continue.

#include <iostream>
#include <cstdlib>
#include <graphics.h>


using namespace std;



int main() {

    int gdriver = 9;
    int gmode = 2;
    int x;
    initgraph(&gdriver, &gmode, "");
    setbkcolor (WHITE);
    setcolor (BLACK);
    cleardevice();
    for (x = 260; x < 364; x = x + 5)
    {
        circle(x,240,60);
    }
    getch();
    closegraph();

    return 0;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
szentmihaly
  • 39
  • 1
  • 13
  • the third argument in `initgraph` is path, which you have kept empty, how will it load the driver then? – piyushj May 05 '16 at 10:24
  • Possible duplicate of [C++ warning: deprecated conversion from string constant to ‘char\*’ \[-Wwrite-strings\]](http://stackoverflow.com/questions/21529194/c-warning-deprecated-conversion-from-string-constant-to-char-wwrite-stri) – HadeS May 05 '16 at 10:54

2 Answers2

0

Without looking inside <graphics.h>, It would appear that initgraph() is declared as taking a (non-const) char* as the third parameter - suggesting that it is an output parameter, pointing to a writeable char array that initgraph() will write to.

As well as producing the warning you've quoted, passing the string constant "" as the argument would result in undefined behaviour, of which crashing is a perfect example.

While my remarks above are valid, after looking at the documentation I would surmise that the parameter is not an output parameter, and that the lack of const is simply poor API implementation - as is the apparent absence of any means to determine whether initialisation actually succeeded or not...

Jeremy
  • 5,055
  • 1
  • 28
  • 44
  • Any thoughts on how to resolve this problem? Many thanks. – szentmihaly May 05 '16 at 14:58
  • More helpfully, I would direct you to the statement in (what I assume is) the documentation that says "if pathtodriver is null, the driver files (*.BGI) must be in the current directory". – Jeremy May 05 '16 at 16:25
  • I have foun the solution, and posted the answer. Anyway, thanks for your time and help! – szentmihaly May 06 '16 at 21:20
0

I have found the solution.

The problem was in the next library:

libbgi.a

I have tried sever different ones, but at the end I found the right one. As soon as I replaced it with the old one - the graphic window opened and worked just fine, without crashes.

The warning:

deprecated conversion from string constant to 'char*' [-Wwrite-strings]|

is still there, but the code works perfectly.

Thanks for help anyway.

Cheers.

szentmihaly
  • 39
  • 1
  • 13