This is a simple code for page flipping in C. The problem is, it works on a friend's computer, but not on mine. We both use the Turbo C++ compiler v3.0. The problem is that if 'i' is set to 0 inside the 'while (!kbhit())' loop, the Page 0 comes up and doesn't go. If 'i' is set to 1, 2, or 3, that page comes for a very short time (less than 1 second), and then Page 0 comes back and stays on the screen. How can I fix this problem?
Code:
#include <conio.h>
#include <dos.h>
#include <graphics.h>
int main(void)
{
int i;
/* request auto detection */
int gdriver = EGA, gmode = EGALO, errorcode;
/* initialize graphics and local
variables */
initgraph(&gdriver, &gmode, "..\\bgi");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/* setting the four pages available in EGALO mode */
setactivepage(0);
cleardevice();
circle(1, 1, 100);
outtextxy(200, 1, "Page 0");
setactivepage(1);
cleardevice();
circle(getmaxx(), 1, 100);
outtextxy(200, 1, "Page 1");
setactivepage(2);
cleardevice();
circle(getmaxx(), getmaxy(), 100);
outtextxy(200, 1, "Page 2");
setactivepage(3);
cleardevice();
circle(1, getmaxy(), 100);
outtextxy(200, 1, "Page 3");
/* looping through the pages */
while (!kbhit())
{
i = 0;
setvisualpage(i);
++i;
if (i == 4)
i = 0;
delay(1000);
}
closegraph();
return 0;
}
[code][/code]tagged by Salem