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

📄 fc.htm

📁 C函数速查。很有用的手册。相信会对大家的编程有用。
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<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>fc</TITLE>
</HEAD>
<BODY bgcolor="#CCCCCC">
<font color="#003399">&nbsp; </font>
<P><font color="#003399">函数名: cabs <BR>
  功&nbsp; 能: 计算复数的绝对值 <BR>
  用&nbsp; 法: double cabs(struct complex z); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;stdio.h> <BR>
  #include &lt;math.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; struct complex z; <BR>
  &nbsp;&nbsp; double val; </font>
<P><font color="#003399">&nbsp;&nbsp; z.x = 2.0; <BR>
  &nbsp;&nbsp; z.y = 1.0; <BR>
  &nbsp;&nbsp; val = cabs(z); </font>
<P><font color="#003399">&nbsp;&nbsp; printf("The absolute value of %.2lfi %.2lfj 
  is %.2lf", z.x, z.y, val); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: calloc <BR>
  功&nbsp; 能: 分配主存储器 <BR>
  用&nbsp; 法: void *calloc(size_t nelem, size_t elsize); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;stdio.h> <BR>
  #include &lt;alloc.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; char *str = NULL; </font>
<P><font color="#003399">&nbsp;&nbsp; /* allocate memory for string */ <BR>
  &nbsp;&nbsp; str = calloc(10, sizeof(char)); </font>
<P><font color="#003399">&nbsp;&nbsp; /* copy "Hello" into string */ <BR>
  &nbsp;&nbsp; strcpy(str, "Hello"); </font>
<P><font color="#003399">&nbsp;&nbsp; /* display string */ <BR>
  &nbsp;&nbsp; printf("String is %s\n", str); </font>
<P><font color="#003399">&nbsp;&nbsp; /* free memory */ <BR>
  &nbsp;&nbsp; free(str); </font>
<P><font color="#003399">&nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: ceil <BR>
  功&nbsp; 能: 向上舍入 <BR>
  用&nbsp; 法: double ceil(double x); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;math.h> <BR>
  #include &lt;stdio.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; double number = 123.54; <BR>
  &nbsp;&nbsp; double down, up; </font>
<P><font color="#003399">&nbsp;&nbsp; down = floor(number); <BR>
  &nbsp;&nbsp; up = ceil(number); </font>
<P><font color="#003399">&nbsp;&nbsp; printf("original number&nbsp;&nbsp;&nbsp;&nbsp; 
  %5.2lf\n", number); <BR>
  &nbsp;&nbsp; printf("number rounded down %5.2lf\n", down); <BR>
  &nbsp;&nbsp; printf("number rounded up&nbsp;&nbsp; %5.2lf\n", up); </font>
<P><font color="#003399">&nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: cgets <BR>
  功&nbsp; 能: 从控制台读字符串 <BR>
  用&nbsp; 法: char *cgets(char *str); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;stdio.h> <BR>
  #include &lt;conio.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; char buffer[83]; <BR>
  &nbsp;&nbsp; char *p; </font>
<P><font color="#003399">&nbsp;&nbsp; /* There's space for 80 characters plus 
  the NULL terminator */ <BR>
  &nbsp;&nbsp; buffer[0] = 81; </font>
<P><font color="#003399">&nbsp;&nbsp; printf("Input some chars:"); <BR>
  &nbsp;&nbsp; p = cgets(buffer); <BR>
  &nbsp;&nbsp; printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p); <BR>
  &nbsp;&nbsp; printf("The returned pointer is %p, buffer[0] is at %p\n", p, &amp;buffer); 
  </font>
<P><font color="#003399">&nbsp;&nbsp; /* Leave room for 5 characters plus the 
  NULL terminator */ <BR>
  &nbsp;&nbsp; buffer[0] = 6; </font>
<P><font color="#003399">&nbsp;&nbsp; printf("Input some chars:"); <BR>
  &nbsp;&nbsp; p = cgets(buffer); <BR>
  &nbsp;&nbsp; printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p); <BR>
  &nbsp;&nbsp; printf("The returned pointer is %p, buffer[0] is at %p\n", p, &amp;buffer); 
  <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: chdir <BR>
  功&nbsp; 能: 改变工作目录 <BR>
  用&nbsp; 法: int chdir(const char *path); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;stdio.h> <BR>
  #include &lt;stdlib.h> <BR>
  #include &lt;dir.h> </font>
<P><font color="#003399">char old_dir[MAXDIR]; <BR>
  char new_dir[MAXDIR]; </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; if (getcurdir(0, old_dir)) <BR>
  &nbsp;&nbsp; { <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("getcurdir()"); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>
  &nbsp;&nbsp; } <BR>
  &nbsp;&nbsp; printf("Current directory is: \\%s\n", old_dir); </font>
<P><font color="#003399">&nbsp;&nbsp; if (chdir("\\")) <BR>
  &nbsp;&nbsp; { <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("chdir()"); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>
  &nbsp;&nbsp; } </font>
<P><font color="#003399">&nbsp;&nbsp; if (getcurdir(0, new_dir)) <BR>
  &nbsp;&nbsp; { <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("getcurdir()"); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>
  &nbsp;&nbsp; } <BR>
  &nbsp;&nbsp; printf("Current directory is now: \\%s\n", new_dir); </font>
<P><font color="#003399">&nbsp;&nbsp; printf("\nChanging back to orignal directory: 
  \\%s\n", old_dir); <BR>
  &nbsp;&nbsp; if (chdir(old_dir)) <BR>
  &nbsp;&nbsp; { <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror("chdir()"); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <BR>
  &nbsp;&nbsp; } </font>
<P><font color="#003399">&nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: _chmod, chmod <BR>
  功&nbsp; 能: 改变文件的访问方式 <BR>
  用&nbsp; 法: int chmod(const char *filename, int permiss); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;sys\stat.h> <BR>
  #include &lt;stdio.h> <BR>
  #include &lt;io.h> </font>
<P><font color="#003399">void make_read_only(char *filename); </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; make_read_only("NOTEXIST.FIL"); <BR>
  &nbsp;&nbsp; make_read_only("MYFILE.FIL"); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } </font>
<P><font color="#003399">void make_read_only(char *filename) <BR>
  { <BR>
  &nbsp;&nbsp; int stat; </font>
<P><font color="#003399">&nbsp;&nbsp; stat = chmod(filename, S_IREAD); <BR>
  &nbsp;&nbsp; if (stat) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Couldn't make %s read-only\n", filename); 
  <BR>
  &nbsp;&nbsp; else <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Made %s read-only\n", filename); <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: chsize <BR>
  功&nbsp; 能: 改变文件大小 <BR>
  用&nbsp; 法: int chsize(int handle, long size); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;string.h> <BR>
  #include &lt;fcntl.h> <BR>
  #include &lt;io.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; int handle; <BR>
  &nbsp;&nbsp; char buf[11] = "0123456789"; </font>
<P><font color="#003399">&nbsp;&nbsp; /* create text file containing 10 bytes 
  */ <BR>
  &nbsp;&nbsp; handle = open("DUMMY.FIL", O_CREAT); <BR>
  &nbsp;&nbsp; write(handle, buf, strlen(buf)); </font>
<P><font color="#003399">&nbsp;&nbsp; /* truncate the file to 5 bytes in size 
  */ <BR>
  &nbsp;&nbsp; chsize(handle, 5); </font>
<P><font color="#003399">&nbsp;&nbsp; /* close the file */ <BR>
  &nbsp;&nbsp; close(handle); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: circle <BR>
  功&nbsp; 能: 在给定半径以(x, y)为圆心画圆 <BR>
  用&nbsp; 法: void far circle(int x, int y, int radius); <BR>
  程序例: </font>
<P><font color="#003399">#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; /* request auto detection */ <BR>
  &nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <BR>
  &nbsp;&nbsp; int midx, midy; <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><font color="#003399">&nbsp;&nbsp; /* read result of initialization */ <BR>
  &nbsp;&nbsp; errorcode = graphresult(); <BR>
  &nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error occurred */ <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(); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* 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 the circle */ <BR>
  &nbsp;&nbsp; circle(midx, midy, 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; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: cleardevice <BR>
  功&nbsp; 能: 清除图形屏幕 <BR>
  用&nbsp; 法: void far cleardevice(void); <BR>
  程序例: </font>
<P><font color="#003399">#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; /* request auto detection */ <BR>
  &nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <BR>
  &nbsp;&nbsp; int midx, midy; </font>
<P><font color="#003399">&nbsp;&nbsp; /* initialize graphics and local variables 
  */ <BR>
  &nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, ""); </font>
<P><font color="#003399">&nbsp;&nbsp; /* read result of initialization */ <BR>
  &nbsp;&nbsp; errorcode = graphresult(); <BR>
  &nbsp;&nbsp; if (errorcode != grOk)&nbsp; /* an error occurred */ <BR>

⌨️ 快捷键说明

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