⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c.htm

📁 C语言函数库,包含所有的C语言函数
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body bgcolor="#00FFFF" text="#000080">

<PRE><font size="5"><a href="a.htm">A</a> <a href="b.htm">B</a> <a href="c.htm">C</a> <a href="d.htm">D</a> <a href="e.htm">E</a> <a href="f.htm">F</a> <a href="g.htm">G</a> <a href="h.htm">H</a> <a href="i.htm">I</a> <a href="k.htm">K</a> <a href="l.htm">L</a> <a href="m.htm">M</a> <a href="n.htm">N</a> <a href="o.htm">O</a> <a href="p.htm">P</a> <a href="q.htm">Q</a> <a href="r.htm">R</a> <a href="s.htm">S</a> <a href="t.htm">T</a> <a href="u.htm">U</a> <a href="v.htm">V</a> <a href="w.htm">W</a></font></PRE>

<PRE>函数大全(c开头)
</PRE>
<PRE>函数名: <font size="5" color="#FF0000">cabs</font> 
功 能: 计算复数的绝对值 
用 法: double cabs(struct complex z); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
struct complex z; 
double val; </PRE>
<PRE>z.x = 2.0; 
z.y = 1.0; 
val = cabs(z); </PRE>
<PRE>printf(&quot;The absolute value of %.2lfi %.2lfj is %.2lf&quot;, z.x, z.y, val); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">calloc </font>
功 能: 分配主存储器 
用 法: void *calloc(size_t nelem, size_t elsize); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *str = NULL; </PRE>
<PRE>/* allocate memory for string */ 
str = calloc(10, sizeof(char)); </PRE>
<PRE>/* copy &quot;Hello&quot; into string */ 
strcpy(str, &quot;Hello&quot;); </PRE>
<PRE>/* display string */ 
printf(&quot;String is %s\n&quot;, str); </PRE>
<PRE>/* free memory */ 
free(str); </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">ceil </font>
功 能: 向上舍入 
用 法: double ceil(double x); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
double number = 123.54; 
double down, up; </PRE>
<PRE>down = floor(number); 
up = ceil(number); </PRE>
<PRE>printf(&quot;original number %5.2lf\n&quot;, number); 
printf(&quot;number rounded down %5.2lf\n&quot;, down); 
printf(&quot;number rounded up %5.2lf\n&quot;, up); </PRE>
<PRE>return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">cgets </font>
功 能: 从控制台读字符串 
用 法: char *cgets(char *str); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char buffer[83]; 
char *p; </PRE>
<PRE>/* There's space for 80 characters plus the NULL terminator */ 
buffer[0] = 81; </PRE>
<PRE>printf(&quot;Input some chars:&quot;); 
p = cgets(buffer); 
printf(&quot;\ncgets read %d characters: \&quot;%s\&quot;\n&quot;, buffer[1], p); 
printf(&quot;The returned pointer is %p, buffer[0] is at %p\n&quot;, p, &amp;buffer); </PRE>
<PRE>/* Leave room for 5 characters plus the NULL terminator */ 
buffer[0] = 6; </PRE>
<PRE>printf(&quot;Input some chars:&quot;); 
p = cgets(buffer); 
printf(&quot;\ncgets read %d characters: \&quot;%s\&quot;\n&quot;, buffer[1], p); 
printf(&quot;The returned pointer is %p, buffer[0] is at %p\n&quot;, p, &amp;buffer); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">chdir </font>
功 能: 改变工作目录 
用 法: int chdir(const char *path); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>char old_dir[MAXDIR]; 
char new_dir[MAXDIR]; </PRE>
<PRE>int main(void) 
{ 
if (getcurdir(0, old_dir)) 
{ 
perror(&quot;getcurdir()&quot;); 
exit(1); 
} 
printf(&quot;Current directory is: \\%s\n&quot;, old_dir); </PRE>
<PRE>if (chdir(&quot;\\&quot;)) 
{ 
perror(&quot;chdir()&quot;); 
exit(1); 
} </PRE>
<PRE>if (getcurdir(0, new_dir)) 
{ 
perror(&quot;getcurdir()&quot;); 
exit(1); 
} 
printf(&quot;Current directory is now: \\%s\n&quot;, new_dir); </PRE>
<PRE>printf(&quot;\nChanging back to orignal directory: \\%s\n&quot;, old_dir); 
if (chdir(old_dir)) 
{ 
perror(&quot;chdir()&quot;); 
exit(1); 
} </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">_chmod</font>
功 能: 改变文件的访问方式 
用 法: int chmod(const char *filename, int permiss); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>void make_read_only(char *filename); </PRE>
<PRE>int main(void) 
{ 
make_read_only(&quot;NOTEXIST.FIL&quot;); 
make_read_only(&quot;MYFILE.FIL&quot;); 
return 0; 
} </PRE>
<PRE>void make_read_only(char *filename) 
{ 
int stat; </PRE>
<PRE>stat = chmod(filename, S_IREAD); 
if (stat) 
printf(&quot;Couldn't make %s read-only\n&quot;, filename); 
else 
printf(&quot;Made %s read-only\n&quot;, filename); 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">chsize </font>
功 能: 改变文件大小 
用 法: int chsize(int handle, long size); 
程序例: </PRE>
<PRE>#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
int handle; 
char buf[11] = &quot;0123456789&quot;; </PRE>
<PRE>/* create text file containing 10 bytes */ 
handle = open(&quot;DUMMY.FIL&quot;, O_CREAT); 
write(handle, buf, strlen(buf)); </PRE>
<PRE>/* truncate the file to 5 bytes in size */ 
chsize(handle, 5); </PRE>
<PRE>/* close the file */ 
close(handle); 
return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> circle </font>
功 能: 在给定半径以(x, y)为圆心画圆 
用 法: void far circle(int x, int y, int radius); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy; 
int radius = 100; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); 
if (errorcode != grOk) /* an error occurred */ 
{ 
printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
exit(1); /* terminate with an error code */ 
} </PRE>
<PRE>midx = getmaxx() / 2; 
midy = getmaxy() / 2; 
setcolor(getmaxcolor()); </PRE>
<PRE>/* draw the circle */ 
circle(midx, midy, radius); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">cleardevice </font>
功 能: 清除图形屏幕 
用 法: void far cleardevice(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int midx, midy; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); 
if (errorcode != grOk) /* an error occurred */ 
{ 
printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
exit(1); /* terminate with an error code */ 
} </PRE>
<PRE>midx = getmaxx() / 2; 
midy = getmaxy() / 2; 
setcolor(getmaxcolor()); </PRE>
<PRE>/* for centering screen messages */ 
settextjustify(CENTER_TEXT, CENTER_TEXT); </PRE>
<PRE>/* output a message to the screen */ 
outtextxy(midx, midy, &quot;press any key to clear the screen:&quot;); </PRE>
<PRE>/* wait for a key */ 
getch(); </PRE>
<PRE>/* clear the screen */ 
cleardevice(); </PRE>
<PRE>/* output another message */ 
outtextxy(midx, midy, &quot;press any key to quit:&quot;); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">clearerr</font> 
功 能: 复位错误标志 
用 法:void clearerr(FILE *stream); 
程序例: </PRE>
<PRE>#include </PRE>
<PRE>int main(void) 
{ 
FILE *fp; 
char ch; </PRE>
<PRE>/* open a file for writing */ 
fp = fopen(&quot;DUMMY.FIL&quot;, &quot;w&quot;); </PRE>
<PRE>/* force an error condition by attempting to read */ 
ch = fgetc(fp); 
printf(&quot;%c\n&quot;,ch); </PRE>
<PRE>if (ferror(fp)) 
{ 
/* display an error message */ 
printf(&quot;Error reading from DUMMY.FIL\n&quot;); </PRE>
<PRE>/* reset the error and EOF indicators */ 
clearerr(fp); 
} </PRE>
<PRE>fclose(fp); 
return 0; 
} 


</PRE>
<PRE>函数名: <font size="5" color="#FF0000">clearviewport</font> 
功 能: 清除图形视区 
用 法: void far clearviewport(void); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>#define CLIP_ON 1 /* activates clipping in viewport */ </PRE>
<PRE>int main(void) 
{ 
/* request auto detection */ 
int gdriver = DETECT, gmode, errorcode; 
int ht; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); 
if (errorcode != grOk) /* an error occurred */ 
{ 
printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
exit(1); /* terminate with an error code */ 
} </PRE>
<PRE>setcolor(getmaxcolor()); 
ht = textheight(&quot;W&quot;); </PRE>
<PRE>/* message in default full-screen viewport */ 
outtextxy(0, 0, &quot;* &lt;-- (0, 0) in default viewport&quot;); </PRE>
<PRE>/* create a smaller viewport */ 
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </PRE>
<PRE>/* display some messages */ 
outtextxy(0, 0, &quot;* &lt;-- (0, 0) in smaller viewport&quot;); 
outtextxy(0, 2*ht, &quot;Press any key to clear viewport:&quot;); </PRE>
<PRE>/* wait for a key */ 
getch(); </PRE>
<PRE>/* clear the viewport */ 
clearviewport(); </PRE>
<PRE>/* output another message */ 
outtextxy(0, 0, &quot;Press any key to quit:&quot;); </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 


</PRE>
<PRE>函数名: _<font size="5" color="#FF0000">close </font>
功 能: 关闭文件句柄 
用 法: int close(int handle); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>main() 
{ 
int handle; 
char buf[11] = &quot;0123456789&quot;; </PRE>
<PRE>/* create a file containing 10 bytes */ 
handle = open(&quot;NEW.FIL&quot;, O_CREAT); 
if (handle &gt; -1) 
{ 
write(handle, buf, strlen(buf)); </PRE>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -