电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> c语言>>C语言库函数(C类字母之二):

C语言库函数(C类字母之二)

来源:www.cncfan.com | 2006-1-16 | (有2409人读过)

printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());

/* draw the circle */
circle(midx, midy, radius);

/* clean up */
getch();
closegraph();
return 0;
}




函数名: cleardevice
功 能: 清除图形屏幕
用 法: void far cleardevice(void);
程序例:

#include
#include
#include
#include

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
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 */
}

midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());

/* for centering screen messages */
settextjustify(CENTER_TEXT, CENTER_TEXT);

/* output a message to the screen */
outtextxy(midx, midy, "press any key to clear the screen:");

/* wait for a key */
getch();

/* clear the screen */
cleardevice();

/* output another message */
outtextxy(midx, midy, "press any key to quit:");

/* clean up */
getch();
closegraph();
return 0;
}




函数名: clearerr
功 能: 复位错误标志
用 法:void clearerr(FILE *stream);
程序例:

#include

int main(void)
{
FILE *fp;
char ch;

/* open a file for writing */
fp = fopen("DUMMY.FIL", "w");

/* force an error condition by attempting to read */
ch = fgetc(fp);
printf("%c\n",ch);

if (ferror(fp))
{
/* display an error message */
printf("Error reading from DUMMY.FIL\n");

/* reset the error and EOF indicators */
clearerr(fp);
}

fclose(fp);
return 0;
}




函数名: clearviewport
功 能: 清除图形视区
用 法: void far clearviewport(void);
程序例:

#include
#include
#include
#include

#define CLIP_ON 1 /* activates clipping in viewport */

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int ht;

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
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 */
}

setcolor(getmaxcolor());
ht = textheight("W");

/* message in default full-screen viewport */
outtextxy(0, 0, "* <-- (0, 0) in default viewport");

/* create a smaller viewport */
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON);

/* display some messages */
outtextxy(0, 0, "* <-- (0, 0) in smaller viewport");
outtextxy(0, 2*ht, "Press any key to clear viewport:");

/* wait for a key */
getch();

/* clear the viewport */
clearviewport();

/* output another message */
outtextxy(0, 0, "Press any key to quit:");

/* clean up */
getch();
closegraph();
return 0;
}




函数名: _close, close
功 能: 关闭文件句柄
用 法: int close(int handle);
程序例:

#include
#include
#include
#include

main()
{
int handle;
char buf[11] = "0123456789";

/* create a file containing 10 bytes */
handle = open("NEW.FIL", O_CREAT);
if (handle > -1)
{
write(handle, buf, strlen(buf));

/* close the file */
close(handle);
}
else
{
printf("Error opening file\n");
}
return 0;
}




函数名: clock
功 能: 确定处理器时间
用 法: clock_t clock(void);
程序例:

#include
#include
#include

int main(void)
{
clock_t start, end;
start = clock();

delay(2000);

end = clock();
printf("The time was: %f\n", (end - start) / CLK_TCK);

return 0;
}




函数名: closegraph
功 能: 关闭图形系统
用 法: void far closegraph(void);
程序例:

#include
#include
#include
c语言热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号