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

📄 fa.htm

📁 C函数速查。很有用的手册。相信会对大家的编程有用。
💻 HTM
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
   <META NAME="Author" CONTENT="wdg">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.03 [en] (Win95; I) [Netscape]">
   <TITLE>fa</TITLE>
<link rel="stylesheet" href="1.css" type="text/css">
</HEAD>
<BODY bgcolor="#CCCCCC">
<font color="#003399">&nbsp; </font>
<P><font color="#003399">函数名: abort <BR>
  功&nbsp; 能: 异常终止一个进程 <BR>
  用&nbsp; 法: void abort(void); <BR>
  程序例: <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;stdlib.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp; printf("Calling abort()\n"); <BR>
  &nbsp; abort(); <BR>
  &nbsp; return 0; /* This is never reached */ <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: abs <BR>
  功&nbsp; 能: 求整数的绝对值 <BR>
  用&nbsp; 法: int abs(int i); <BR>
  程序例: <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;math.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp; int number = -1234; </font>
<P><font color="#003399">&nbsp; printf("number: %d&nbsp; absolute value: %d\n", 
  number, abs(number)); <BR>
  &nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: absread, abswirte <BR>
  功&nbsp; 能: 绝对磁盘扇区读、写数据 <BR>
  用&nbsp; 法: int absread(int drive, int nsects, int sectno, void *buffer); <BR>
  &nbsp;int abswrite(int drive, int nsects, in tsectno, void *buffer); <BR>
  程序例: <BR>
  /* absread example */ </font>
<P><font color="#003399">#include &lt;stdio.h> <BR>
  #include &lt;conio.h> <BR>
  #include &lt;process.h> <BR>
  #include &lt;dos.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp; int i, strt, ch_out, sector; <BR>
  &nbsp; char buf[512]; </font>
<P><font color="#003399">&nbsp; printf("Insert a diskette into drive A and press 
  any key\n"); <BR>
  &nbsp; getch(); <BR>
  &nbsp; sector = 0; <BR>
  &nbsp; if (absread(0, 1, sector, &amp;buf) != 0) <BR>
  &nbsp; { <BR>
  &nbsp;&nbsp;&nbsp;&nbsp; perror("Disk problem"); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>
  &nbsp; } <BR>
  &nbsp; printf("Read OK\n"); <BR>
  &nbsp; strt = 3; <BR>
  &nbsp; for (i=0; i&lt;80; i++) <BR>
  &nbsp; { <BR>
  &nbsp;&nbsp;&nbsp;&nbsp; ch_out = buf[strt+i]; <BR>
  &nbsp;&nbsp;&nbsp;&nbsp; putchar(ch_out); <BR>
  &nbsp; } <BR>
  &nbsp; printf("\n"); <BR>
  &nbsp; return(0); <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: access <BR>
  功&nbsp; 能: 确定文件的访问权限 <BR>
  用&nbsp; 法: int access(const char *filename, int amode); <BR>
  程序例: <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;io.h> </font>
<P><font color="#003399">int file_exists(char *filename); </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp; printf("Does NOTEXIST.FIL exist: %s\n", <BR>
  &nbsp; file_exists("NOTEXISTS.FIL") ? "YES" : "NO"); <BR>
  &nbsp; return 0; <BR>
  } </font>
<P><font color="#003399">int file_exists(char *filename) <BR>
  { <BR>
  &nbsp; return (access(filename, 0) == 0); <BR>
  } <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: acos <BR>
  功&nbsp; 能: 反余弦函数 <BR>
  用&nbsp; 法: double acos(double x); <BR>
  程序例: <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;math.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp; double result; <BR>
  &nbsp; double x = 0.5; </font>
<P><font color="#003399">&nbsp; result = acos(x); <BR>
  &nbsp; printf("The arc cosine of %lf is %lf\n", x, result); <BR>
  &nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: allocmem <BR>
  功&nbsp; 能: 分配DOS存储段 <BR>
  用&nbsp; 法: int allocmem(unsigned size, unsigned *seg); <BR>
  程序例: <BR>
  #include &lt;dos.h> <BR>
  #include &lt;alloc.h> <BR>
  #include &lt;stdio.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp; unsigned int size, segp; <BR>
  &nbsp; int stat; </font>
<P><font color="#003399">&nbsp; size = 64; /* (64 x 16) = 1024 bytes */ <BR>
  &nbsp; stat = allocmem(size, &amp;segp); <BR>
  &nbsp; if (stat == -1) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp; printf("Allocated memory at segment: %x\n", segp); 
  <BR>
  &nbsp; else <BR>
  &nbsp;&nbsp;&nbsp;&nbsp; printf("Failed: maximum number of paragraphs available 
  is %u\n", <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stat); </font>
<P><font color="#003399">&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: arc <BR>
  功&nbsp; 能: 画一弧线 <BR>
  用&nbsp; 法: void far arc(int x, int y, int stangle, int endangle, int radius); 
  <BR>
  程序例: <BR>
  #include &lt;graphics.h> <BR>
  #include &lt;stdlib.h> <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;conio.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp;&nbsp; /* request auto detection */ <BR>
  &nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <BR>
  &nbsp;&nbsp; int midx, midy; <BR>
  &nbsp;&nbsp; int stangle = 45, endangle = 135; <BR>
  &nbsp;&nbsp; int radius = 100; </font>
<P><font color="#003399">&nbsp;&nbsp; /* initialize graphics and local variables 
  */ <BR>
  &nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, ""); </font>
<P class="未命名1"><font color="#003399">&nbsp;&nbsp; /* read result of initialization 
  */ <BR>
  &nbsp;&nbsp; errorcode = graphresult();&nbsp;&nbsp;&nbsp; /* an error occurred 
  */ <BR>
  &nbsp;&nbsp; if (errorcode != grOk) <BR>
  &nbsp;&nbsp; { <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n", grapherrormsg(errorcode)); 
  <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:"); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); </font>
<P><font color="#003399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);&nbsp;&nbsp;&nbsp; 
  /* terminate with an error code */ <BR>
  &nbsp;&nbsp; } </font>
<P><font color="#003399">&nbsp;&nbsp; midx = getmaxx() / 2; <BR>
  &nbsp;&nbsp; midy = getmaxy() / 2; <BR>
  &nbsp;&nbsp; setcolor(getmaxcolor()); </font>
<P><font color="#003399">&nbsp;&nbsp; /* draw arc */ <BR>
  &nbsp;&nbsp; arc(midx, midy, stangle, endangle, radius); </font>
<P><font color="#003399">&nbsp;&nbsp; /* clean up */ <BR>
  &nbsp;&nbsp; getch(); <BR>
  &nbsp;&nbsp; closegraph(); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: asctime <BR>
  功&nbsp; 能: 转换日期和时间为ASCII码 <BR>
  用&nbsp; 法: char *asctime(const struct tm *tblock); <BR>
  程序例: <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;string.h> <BR>
  #include &lt;time.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; struct tm t; <BR>
  &nbsp;&nbsp; char str[80]; </font>
<P><font color="#003399">&nbsp;&nbsp; /* sample loading of tm structure&nbsp; 
  */ </font>
<P><font color="#003399">&nbsp;&nbsp; t.tm_sec&nbsp;&nbsp;&nbsp; = 1;&nbsp; /* 
  Seconds */ <BR>
  &nbsp;&nbsp; t.tm_min&nbsp;&nbsp;&nbsp; = 30; /* Minutes */ <BR>
  &nbsp;&nbsp; t.tm_hour&nbsp;&nbsp; = 9;&nbsp; /* Hour */ <BR>
  &nbsp;&nbsp; t.tm_mday&nbsp;&nbsp; = 22; /* Day of the Month&nbsp; */ <BR>
  &nbsp;&nbsp; t.tm_mon&nbsp;&nbsp;&nbsp; = 11; /* Month */ <BR>
  &nbsp;&nbsp; t.tm_year&nbsp;&nbsp; = 56; /* Year - does not include century 
  */ <BR>
  &nbsp;&nbsp; t.tm_wday&nbsp;&nbsp; = 4;&nbsp; /* Day of the week&nbsp; */ <BR>
  &nbsp;&nbsp; t.tm_yday&nbsp;&nbsp; = 0;&nbsp; /* Does not show in asctime&nbsp; 
  */ <BR>
  &nbsp;&nbsp; t.tm_isdst&nbsp; = 0;&nbsp; /* Is Daylight SavTime; does not show 
  in asctime */ </font>
<P><font color="#003399">&nbsp;&nbsp; /* converts structure to null terminated 
  <BR>
  &nbsp;&nbsp; string */ </font>
<P><font color="#003399">&nbsp;&nbsp; strcpy(str, asctime(&amp;t)); <BR>
  &nbsp;&nbsp; printf("%s\n", str); </font>
<P><font color="#003399">&nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: asin <BR>
  功&nbsp; 能: 反正弦函数 <BR>
  用&nbsp; 法: double asin(double x); <BR>
  程序例: <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;math.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; double result; <BR>
  &nbsp;&nbsp; double x = 0.5; </font>
<P><font color="#003399">&nbsp;&nbsp; result = asin(x); <BR>
  &nbsp;&nbsp; printf("The arc sin of %lf is %lf\n", x, result); <BR>
  &nbsp;&nbsp; return(0); <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: assert <BR>
  功&nbsp; 能: 测试一个条件并可能使程序终止 <BR>
  用&nbsp; 法: void assert(int test); <BR>
  程序例: <BR>
  #include &lt;assert.h> <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;stdlib.h> </font>
<P><font color="#003399">struct ITEM { <BR>
  &nbsp;&nbsp; int key; <BR>
  &nbsp;&nbsp; int value; <BR>
  }; </font>
<P><font color="#003399">/* add item to list, make sure list is not null */ <BR>
  void additem(struct ITEM *itemptr) { <BR>
  &nbsp;&nbsp; assert(itemptr != NULL); <BR>
  &nbsp;&nbsp; /* add item to list */ <BR>
  } </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; additem(NULL); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: atan <BR>
  功&nbsp; 能: 反正切函数 <BR>
  用&nbsp; 法: double atan(double x); <BR>
  程序例: <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;math.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; double result; <BR>
  &nbsp;&nbsp; double x = 0.5; </font>
<P><font color="#003399">&nbsp;&nbsp; result = atan(x); <BR>
  &nbsp;&nbsp; printf("The arc tangent of %lf is %lf\n", x, result); <BR>
  &nbsp;&nbsp; return(0); <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: atan2 <BR>
  功&nbsp; 能: 计算Y/X的反正切值 <BR>
  用&nbsp; 法: double atan2(double y, double x); <BR>
  程序例: <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;math.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; double result; <BR>
  &nbsp;&nbsp; double x = 90.0, y = 45.0; </font>
<P><font color="#003399">&nbsp;&nbsp; result = atan2(y, x); <BR>
  &nbsp;&nbsp; printf("The arc tangent ratio of %lf is %lf\n", (y / x), result); 
  <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: atexit <BR>
  功&nbsp; 能: 注册终止函数 <BR>
  用&nbsp; 法: int atexit(atexit_t func); <BR>
  程序例: <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;stdlib.h> </font>
<P><font color="#003399">void exit_fn1(void) <BR>
  { <BR>
  &nbsp;&nbsp; printf("Exit function #1 called\n"); <BR>
  } </font>
<P><font color="#003399">void exit_fn2(void) <BR>
  { <BR>
  &nbsp;&nbsp; printf("Exit function #2 called\n"); <BR>
  } </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; /* post exit function #1 */ <BR>
  &nbsp;&nbsp; atexit(exit_fn1); <BR>
  &nbsp;&nbsp; /* post exit function #2 */ <BR>
  &nbsp;&nbsp; atexit(exit_fn2); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: atof <BR>
  功&nbsp; 能: 把字符串转换成浮点数 <BR>
  用&nbsp; 法: double atof(const char *nptr); <BR>
  程序例: <BR>
  #include &lt;stdlib.h> <BR>
  #include &lt;stdio.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; float f; <BR>
  &nbsp;&nbsp; char *str = "12345.67"; </font>
<P><font color="#003399">&nbsp;&nbsp; f = atof(str); <BR>
  &nbsp;&nbsp; printf("string = %s float = %f\n", str, f); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: atoi <BR>
  功&nbsp; 能: 把字符串转换成长整型数 <BR>
  用&nbsp; 法: int atoi(const char *nptr); <BR>
  程序例: <BR>
  #include &lt;stdlib.h> <BR>
  #include &lt;stdio.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; int n; <BR>
  &nbsp;&nbsp; char *str = "12345.67"; </font>
<P><font color="#003399">&nbsp;&nbsp; n = atoi(str); <BR>
  &nbsp;&nbsp; printf("string = %s integer = %d\n", str, n); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: atol <BR>
  功&nbsp; 能: 把字符串转换成长整型数 <BR>
  用&nbsp; 法: long atol(const char *nptr); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;stdlib.h> <BR>
  #include &lt;stdio.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; long l; <BR>
  &nbsp;&nbsp; char *str = "98765432"; </font>
<P class="未命名1"><font color="#003399">&nbsp;&nbsp; l = atol(lstr); <BR>
  &nbsp;&nbsp; printf("string = %s integer = %ld\n", str, l); <BR>
  &nbsp;&nbsp; return(0); <BR>
  } <BR>
  &nbsp; </font>
<P><font color="#003399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  <A HREF="cyyhsdq.htm">返回</A> </font>
<P><font color="#003399"> </font>
</BODY>
</HTML>

⌨️ 快捷键说明

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