Friday, February 19, 2010

G r a p h i c s


----------------------------------------------------------------------

Q. Why do I get the error message:

BGI Error: graphics not initialized (use 'initgraph')

when I use a graphics function? My program has already

called initgraph().

A. For some reason initgraph() failed. To find out why, check

the return value of graphresult(). For example:

#include

int main(void)

{

int gerr; /* graphics error */

int gdriver = DETECT, gmode;

/* Initialize graphics using auto-detection and look

for the .BGI and .CHR files in the C:\TC\BGI directory.

*/

initgraph(&gdriver, &gmode, "C:\\TC\\BGI");

if ((gerr = graphresult()) != grOk)

{

printf("Error : %s\n", grapherrormsg(gerr));

exit(1);

}

:

}

M a t h / F l o a t i n g P o i n t

----------------------------------------------------------------------

Q. Why do I get incorrect results from all the math library

functions like cos(), tan() and atof()?

A. You must #include before you call any of the standard

Turbo C++ math functions. In general, Turbo C++ assumes that a function

that is not declared returns an int. In the case of math functions,

they usually return a double. For example

/* WRONG */ /* RIGHT */

#include

int main(void) int main(void)

{ {

printf("%f", cos(0)); printf("%f", cos(0));

} }

Q. How do I "trap" a floating-point error?

A. See the signal() and matherr() functions in the online help. The

signal() function may be used to trap errors in the 80x87 or the

80x87 emulator. The matherr() function traps errors in the Math

Library functions.

No comments:

Post a Comment