0
#include <graphics.h>
#include <conio.h>
void main()
{
    int gd=DETECT,gm;
    initgraph(&gd,&gm,"c:\\TURBOC3\\");
    setbkcolor(CYAN);
    getch();
    closegraph();
}

The compiling was successful and tried running it, but the result was I see no display for my code It's just a blink of screen and gone back to the console.

enter image description here

Melebius
  • 6,183
  • 4
  • 39
  • 52
alkhemet
  • 3
  • 8
  • 6
    #rip turbo c++ switch to gcc/g++ (codeblocks/visual studio//devc++) – udit043 Dec 19 '17 at 12:21
  • add second getch maybe, sometimes it needs two, three. depends on OS – tohaz Dec 19 '17 at 12:23
  • 1
    @tohaz done but nothing change. – alkhemet Dec 19 '17 at 12:30
  • 1
    @udit043 I'm using turbo c++ cause this is what we're using in our school. – alkhemet Dec 19 '17 at 12:32
  • 3
    Request your teacher to use devc++/codeblocks bcz https://stackoverflow.com/questions/1961828/why-should-i-not-use-turbo-c – udit043 Dec 19 '17 at 12:35
  • 3
    lets change school – Jacek Cz Dec 19 '17 at 12:36
  • Maybe you need `clrscr()` to clear the screen and fill it with new color. – i486 Dec 19 '17 at 12:44
  • @alkhemet - There is a problem in that those of us who once used Turbo-C++ stopped doing that about 25 years ago. So we simply don't remember enough to help you with these problems. The second problem is that you now learn things that you will have no use for outside school. Sad! – Bo Persson Dec 19 '17 at 12:45
  • 1
    PS: In the good days of Borland C++ (this IDE) there was no Internet and the compiler includes good Help system. Read it, read books. No need to ask for every little step here - otherwise you will not learn to program. – i486 Dec 19 '17 at 12:47
  • i get graphics not initialized error. just put your getch after each line, its a simpliest debug method we used back then – tohaz Dec 19 '17 at 12:55
  • @tohaz No, please! Even Turbo C++ seems to have breakpoints. https://www.wikihow.com/Debug-a-C%2B%2B-Program – Melebius Dec 19 '17 at 12:57
  • @BoPersson It still has it use depends on the person on how he can apply it. It'll just be my first PL to help me understand how to code. Getting my grades high and preparing for other PL that I want to learn. I think It'll have no big difference on using other IDE for C++. – alkhemet Dec 19 '17 at 13:07
  • @alkhemet Yes, to some extent. However, please keep in mind that you are learning a non-standard dialect of the C++ language together with non-standard libraries (like `graphics.h` aka [BGI](https://stackoverflow.com/tags/bgi/info)). – Melebius Dec 19 '17 at 14:41
  • Possible duplicate of [Graphical functions in C](https://stackoverflow.com/questions/34219457/graphical-functions-in-c) – Ravinder Singh Jun 29 '18 at 03:46

2 Answers2

0

you need to point initgraph to bgi subfolder of turboc3

initgraph(&gd,&gm,"c:\\TURBOC3\\BGI");
tohaz
  • 197
  • 5
  • 19
0

Yes your code may compile successfully but your code is having a runtime problem. Just add these line first below the line you initialized your graphics.

int errorcode = graphresult();

if (errorcode != grOk) {  /* an error occurred */
  printf("Graphics error: %s\n", grapherrormsg(errorcode));
  printf("Press any key to halt:");

  getch();
  exit(1);   /* terminate with an error code(requires process.h) */
}

Through these lines runtime problems of graphics can be detected. Its just a safety method for avoid errors and system crash. Well these lines will tell you that they cannot find the file VGAEGA.bgi file. That's generally the default drivers of graphics.

The reason the file is not found is your path c:\\TURBOC3\\. see this post for avoiding the errors.