C++/Graphics initialising error
Expert: Zlatko - 11/13/2009
QuestionSir,I am using Turbo c++. While running the graphics programs I am getting BGI error as "graphics not initialized(use initgraph)". How can I solve this problem sir.
this is my code for your reference....
-----------------------------------------------------------
#include<iostream.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<dos.h>
void main()
{
clrscr();
int gd=0,gm=0,xmin=0,xmax=604,ymin=0,ymax=478;
float i,j,a=302,b=239;
initgraph(&gd,&gm,"..//bgi");
for(i=1;i<=10;i++)
{ settextstyle(SANS_SERIF_FONT, HORIZ_DIR, i);
outtextxy(270,150,"S");
delay(300);
}
closegraph();
clrscr();
initgraph(&gd,&gm,"..//bgi");
for(i=1;i<=10;i++)
{ settextstyle(SANS_SERIF_FONT, HORIZ_DIR, i);
outtextxy(270,150,"T");
delay(300);
}
closegraph();
clrscr();
initgraph(&gd,&gm,"..//bgi");
for(i=1;i<=10;i++)
{ settextstyle(SANS_SERIF_FONT, HORIZ_DIR, i);
outtextxy(270,150,"O");
delay(300);
}
closegraph();
clrscr();
initgraph(&gd,&gm,"..//bgi");
for(i=1;i<=10;i++)
{ settextstyle(SANS_SERIF_FONT, HORIZ_DIR, i);
outtextxy(270,150,"P");
delay(300);
}
closegraph();
clrscr();
initgraph(&gd,&gm,"..//bgi");
for(i=1;i<=10;i++)
{ settextstyle(SANS_SERIF_FONT, HORIZ_DIR, i);
outtextxy(270,150,"I");
delay(300);
}
closegraph();
clrscr();
initgraph(&gd,&gm,"..//bgi");
for(i=1;i<=10;i++)
{ settextstyle(SANS_SERIF_FONT, HORIZ_DIR, i);
outtextxy(270,150,"T");
delay(300);
}
closegraph();
clrscr();
initgraph(&gd,&gm,"..//bgi");
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 5);
outtextxy(100,150,"!! S T O P I T !!");
//302,239 is the origin j-239
getch();
closegraph();
}
AnswerPerhaps you are not calling initgraph correctly.
initgraph(&gd,&gm,"..//bgi");
The // indicates a start of comment in C++
You should use just 1 slash "../bgi"
You need a double slash when you specify a file like this "..\\bgi"
The double slash "\\" is necessary because the single slash "\" is an escape character in C/C++.
If that is not the issue, then I cannot help you further because I don't have access to Turbo C++ and I don't know anything about the Turbo graphics.
Best regards
Zlatko