找回密码

碧海潮声大学生网

楼主: 墙角野猫
打印 上一主题 下一主题

c语言函数大全

[复制链接]
41#
 楼主| 发表于 2006-7-12 22:54 | 只看该作者
函数名: 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
",ch);
if (ferror(fp))
{
/* display an error message */
printf("Error reading from DUMMY.FIL
");
/* reset the error and EOF indicators */
clearerr(fp);
}
fclose(fp);
return 0;
}
42#
 楼主| 发表于 2006-7-12 22:55 | 只看该作者
函数名: 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
", 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;
}
43#
 楼主| 发表于 2006-7-12 22:56 | 只看该作者
函数名: _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
");
}
return 0;
}
44#
 楼主| 发表于 2006-7-12 22:56 | 只看该作者
函数名: 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
", (end - start) / CLK_TCK);
return 0;
}
45#
 楼主| 发表于 2006-7-12 22:57 | 只看该作者
函数名: closegraph
功 能: 关闭图形系统
用 法: void far closegraph(void);
程序例:
#include
#include
#include
#include
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int x, y;
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error
occurred */
{
printf("Graphics error: %s
", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
x = getmaxx() / 2;
y = getmaxy() / 2;
/* output a message */
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(x, y, "Press a key to close the graphics system:");
/* wait for a key */
getch();
/* closes down the graphics system */
closegraph();
printf("We&#39;re now back in text mode.
");
printf("Press any key to halt:");
getch();
return 0;
}
46#
 楼主| 发表于 2006-7-12 22:58 | 只看该作者
函数名: clreol
功 能: 在文本窗口中清除字符到行末
用 法: void clreol(void);
程序例:
#include
int main(void)
{
clrscr();
cprintf("The function CLREOL clears all characters from the\r
");
cprintf("cursor position to the end of the line within the\r
");
cprintf("current text window, without moving the cursor.\r
");
cprintf("Press any key to continue . . .");
gotoxy(14, 4);
getch();
clreol();
getch();
return 0;
}
47#
 楼主| 发表于 2006-7-12 22:58 | 只看该作者
函数名: clrscr
功 能: 清除文本模式窗口
用 法: void clrscr(void);
程序例:
#include
int main(void)
{
int i;
clrscr();
for (i = 0; i < 20; i++)
cprintf("%d\r
", i);
cprintf("\r
Press any key to clear screen");
getch();
clrscr();
cprintf("The screen has been cleared!");
getch();
return 0;
}
48#
 楼主| 发表于 2006-7-12 22:59 | 只看该作者
函数名: coreleft
功 能: 返回未使用内存的大小
用 法: unsigned coreleft(void);
程序例:
#include
#include
int main(void)
{
printf("The difference between the highest allocated block and
");
printf("the top of the heap is: %lu bytes
", (unsigned long) coreleft());
return 0;
}
49#
 楼主| 发表于 2006-7-12 22:59 | 只看该作者
函数名: cos
功 能: 余弦函数
用 法: double cos(double x);
程序例:
#include
#include
int main(void)
{
double result;
double x = 0.5;
result = cos(x);
printf("The cosine of %lf is %lf
", x, result);
return 0;
}
50#
 楼主| 发表于 2006-7-12 23:00 | 只看该作者
函数名: cosh
功 能: 双曲余弦函数
用 法: dluble cosh(double x);
程序例:
#include
#include
int main(void)
{
double result;
double x = 0.5;
result = cosh(x);
printf("The hyperboic cosine of %lf is %lf
", x, result);
return 0;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋| 碧海潮声大学生网  

Copyright © 2001-2013 Comsenz Inc.   All Rights Reserved.

Powered by Discuz! X3.2( 浙ICP备11026473号 )

快速回复 返回顶部 返回列表