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

📄 fb.htm

📁 C函数速查。很有用的手册。相信会对大家的编程有用。
💻 HTM
📖 第 1 页 / 共 2 页
字号:
  功&nbsp; 能: 检查设备 <BR>
  用&nbsp; 法: int biosequip(void); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;bios.h> <BR>
  #include &lt;stdio.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; int result; <BR>
  &nbsp;&nbsp; char buffer[512]; </font>
<P><font color="#003399">&nbsp;&nbsp; printf("Testing to see if drive a: is ready\n"); 
  <BR>
  &nbsp;&nbsp; result = biosdisk(4,0,0,0,0,1,buffer); <BR>
  &nbsp;&nbsp; result &amp;= 0x02; <BR>
  &nbsp;&nbsp; (result) ? (printf("Drive A: Ready\n")) : <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (printf("Drive A: Not Ready\n")); </font>
<P><font color="#003399">&nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: bioskey <BR>
  功&nbsp; 能: 直接使用BIOS服务的键盘接口 <BR>
  用&nbsp; 法: int bioskey(int cmd); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;stdio.h> <BR>
  #include &lt;bios.h> <BR>
  #include &lt;ctype.h> </font>
<P><font color="#003399">#define RIGHT&nbsp; 0x01 <BR>
  #define LEFT&nbsp;&nbsp; 0x02 <BR>
  #define CTRL&nbsp;&nbsp; 0x04 <BR>
  #define ALT&nbsp;&nbsp;&nbsp; 0x08 </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; int key, modifiers; </font>
<P><font color="#003399">&nbsp;&nbsp; /* function 1 returns 0 until a key is pressed 
  */ <BR>
  &nbsp;&nbsp; while (bioskey(1) == 0); </font>
<P><font color="#003399">&nbsp;&nbsp; /* function 0 returns the key that is waiting 
  */ <BR>
  &nbsp;&nbsp; key = bioskey(0); </font>
<P><font color="#003399">&nbsp;&nbsp; /* use function 2 to determine if shift 
  keys were used */ <BR>
  &nbsp;&nbsp; modifiers = bioskey(2); <BR>
  &nbsp;&nbsp; if (modifiers) <BR>
  &nbsp;&nbsp; { <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("["); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (modifiers &amp; RIGHT) printf("RIGHT"); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (modifiers &amp; LEFT)&nbsp; printf("LEFT"); 
  <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (modifiers &amp; CTRL)&nbsp; printf("CTRL"); 
  <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (modifiers &amp; ALT)&nbsp;&nbsp; printf("ALT"); 
  <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("]"); <BR>
  &nbsp;&nbsp; } <BR>
  &nbsp;&nbsp; /* print out the character read */ <BR>
  &nbsp;&nbsp; if (isalnum(key &amp; 0xFF)) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("'%c'\n", key); <BR>
  &nbsp;&nbsp; else <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%#02x\n", key); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: biosmemory <BR>
  功&nbsp; 能: 返回存储块大小 <BR>
  用&nbsp; 法:int biosmemory(void); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;stdio.h> <BR>
  #include &lt;bios.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; int memory_size; </font>
<P><font color="#003399">&nbsp;&nbsp; memory_size = biosmemory();&nbsp; /* returns 
  value up to 640K */ <BR>
  &nbsp;&nbsp; printf("RAM size = %dK\n",memory_size); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: biosprint <BR>
  功&nbsp; 能: 直接使用BIOS服务的打印机I/O <BR>
  用&nbsp; 法: int biosprint(int cmd, int byte, int port); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;stdio.h> <BR>
  #include &lt;conio.h> <BR>
  #include &lt;bios.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; #define STATUS&nbsp; 2&nbsp;&nbsp;&nbsp; /* printer status command 
  */ <BR>
  &nbsp;&nbsp; #define PORTNUM 0&nbsp;&nbsp;&nbsp; /* port number for LPT1 */ 
  </font>
<P><font color="#003399">&nbsp;&nbsp; int status, abyte=0; </font>
<P><font color="#003399">&nbsp;&nbsp; printf("Please turn off your printer.&nbsp; 
  Press any key to continue\n"); <BR>
  &nbsp;&nbsp; getch(); <BR>
  &nbsp;&nbsp; status = biosprint(STATUS, abyte, PORTNUM); <BR>
  &nbsp;&nbsp; if (status &amp; 0x01) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Device time out.\n"); <BR>
  &nbsp;&nbsp; if (status &amp; 0x08) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("I/O error.\n"); </font>
<P><font color="#003399">&nbsp;&nbsp; if (status &amp; 0x10) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Selected.\n"); <BR>
  &nbsp;&nbsp; if (status &amp; 0x20) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Out of paper.\n"); </font>
<P><font color="#003399">&nbsp;&nbsp; if (status &amp; 0x40) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Acknowledge.\n"); <BR>
  &nbsp;&nbsp; if (status &amp; 0x80) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Not busy.\n"); </font>
<P><font color="#003399">&nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: biostime <BR>
  功&nbsp; 能: 读取或设置BIOS时间 <BR>
  用&nbsp; 法: long biostime(int cmd, long newtime); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;stdio.h> <BR>
  #include &lt;bios.h> <BR>
  #include &lt;time.h> <BR>
  #include &lt;conio.h> </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; long bios_time; </font>
<P><font color="#003399">&nbsp;&nbsp; clrscr(); <BR>
  &nbsp;&nbsp; cprintf("The number of clock ticks since midnight is:\r\n"); <BR>
  &nbsp;&nbsp; cprintf("The number of seconds since midnight is:\r\n"); <BR>
  &nbsp;&nbsp; cprintf("The number of minutes since midnight is:\r\n"); <BR>
  &nbsp;&nbsp; cprintf("The number of hours since midnight is:\r\n"); <BR>
  &nbsp;&nbsp; cprintf("\r\nPress any key to quit:"); <BR>
  &nbsp;&nbsp; while(!kbhit()) <BR>
  &nbsp;&nbsp; { <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bios_time = biostime(0, 0L); </font>
<P><font color="#003399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gotoxy(50, 1); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cprintf("%lu", bios_time); </font>
<P><font color="#003399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gotoxy(50, 2); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cprintf("%.4f", bios_time / CLK_TCK); </font>
<P><font color="#003399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gotoxy(50, 3); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cprintf("%.4f", bios_time / CLK_TCK / 60); </font>
<P><font color="#003399">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gotoxy(50, 4); <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cprintf("%.4f", bios_time / CLK_TCK / 3600); 
  <BR>
  &nbsp;&nbsp; } <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: brk <BR>
  功&nbsp; 能: 改变数据段空间分配 <BR>
  用&nbsp; 法: int brk(void *endds); <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 *ptr; </font>
<P><font color="#003399">&nbsp;&nbsp; printf("Changing allocation with brk()\n"); 
  <BR>
  &nbsp;&nbsp; ptr = malloc(1); <BR>
  &nbsp;&nbsp; printf("Before brk() call: %lu bytes free\n", coreleft()); <BR>
  &nbsp;&nbsp; brk(ptr+1000); <BR>
  &nbsp;&nbsp; printf(" After brk() call: %lu bytes free\n", coreleft()); <BR>
  &nbsp;&nbsp; return 0; <BR>
  } <BR>
  &nbsp; <BR>
  &nbsp; <BR>
  &nbsp; </font>
<P><font color="#003399">函数名: bsearch <BR>
  功&nbsp; 能: 二分法搜索 <BR>
  用&nbsp; 法: void *bsearch(const void *key, const void *base, size_t *nelem, <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; size_t width, int(*fcmp)(const void 
  *, const *)); <BR>
  程序例: </font>
<P><font color="#003399">#include &lt;stdlib.h> <BR>
  #include &lt;stdio.h> </font>
<P><font color="#003399">#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </font>
<P><font color="#003399">int numarray[] = {123, 145, 512, 627, 800, 933}; </font>
<P><font color="#003399">int numeric (const int *p1, const int *p2) <BR>
  { <BR>
  &nbsp;&nbsp; return(*p1 - *p2); <BR>
  } </font>
<P><font color="#003399">int lookup(int key) <BR>
  { <BR>
  &nbsp;&nbsp; int *itemptr; </font>
<P><font color="#003399">&nbsp;&nbsp; /* The cast of (int(*)(const void *,const 
  void*)) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; is needed to avoid a type mismatch error at <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; compile time */ <BR>
  &nbsp;&nbsp; itemptr = bsearch (&amp;key, numarray, NELEMS(numarray), <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sizeof(int), (int(*)(const void *,const void 
  *))numeric); <BR>
  &nbsp;&nbsp; return (itemptr != NULL); <BR>
  } </font>
<P><font color="#003399">int main(void) <BR>
  { <BR>
  &nbsp;&nbsp; if (lookup(512)) <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("512 is in the table.\n"); <BR>
  &nbsp;&nbsp; else <BR>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("512 isn't in the table.\n"); </font>
<P><font color="#003399">&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 + -