头文件graphics.h包含grapherrormsg()函数,该函数返回错误消息字符串。
句法 :
char *grapherrormsg( int errorcode );
where,
errorcode: code for the respective error
grapherrormsg()的插图:在下面的程序中,未编写gd = DETECT,因此程序必须抛出错误。
下面是C中grapherrormsg()函数的实现
// C Implementation for grapherrormsg()
#include
#include
//driver code
int main()
{
// gm is Graphics mode which is
// a computer display mode that
// generates image using pixels.
// DETECT is a macro defined in
// "graphics.h" header file
int gd, gm, errorcode;
// initgraph initializes the
// graphics system by loading a
// graphics driver from disk
initgraph(&gd, &gm, "");
// graphresult returns the error code
// for the last graphics operation
// that reported an error and resets
// the error level to grOk.
errorcode = graphresult();
if( errorcode != grOk)
{
printf("Graphics error: %s\n",
grapherrormsg(errorcode));
printf("Press any key to exit.");
getch();
exit(1);
}
getch();
// closegraph function closes the
// graphics mode and deallocates
// all memory allocated by
// graphics system .
closegraph();
return 0;
}
输出 :
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。