function in Graphics. h

Asked

Viewed 361 times

1

I’m trying to learn a little more from C/C++ libraries to do more things so I went after the Graphics library. and went after the most basic code I found, which was:

#include <graphics.h>

int main(){
    int gdriver = DETECT, gmode, errorcode;

    char *str = new char[30];
    strcpy(str, "d:\\tc\\bgi");
    initgraph(&gdriver,&gmode, str);

    arc(200, 200, 0, 130, 50);

    closegraph();

    return 0;
}

What happens is that the program compiled, opened, stopped responding without executing what I asked and closed

  • "without executing what I asked for"'? Try running the program in debug mode, instruction and instruction.

  • No, it doesn’t really run, I used system("PAUSE"); and it doesn’t even run the command, then I debugged in hand passing several lines as a comment and found that the error is in the initgraph function();

  • One remark: It is a good practice to initialize variables. What is the value of the variable gmode?

  • I understand it is, but like I said, I just copied what the guy did, for it worked and for me not.

1 answer

1

I was having the same problem, even installing the graphics.h correctly, the code was compiled and a few seconds after it appeared, the console screen stopped responding out of nowhere, I discovered that the problem was the file "libbgi.a", try to download this and replace it in the folder "lib" compiler.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.