|
Turbo C 2.0、Borland C++库函数及用例(8) printf("Acknowledge.\n"); if (status & 0x80) printf("Not busy.\n"); return 0; } 函数名: biostime 功 能: 读取或设置BIOS时间 用 法: long biostime(int cmd, long newtime); 程序例:#include <stdio.h> #include <bios.h> #include <time.h> #include <conio.h>int main(void) { long bios_time; clrscr(); cprintf("The number of clock ticks since midnight\ is:\r\n"); cprintf("The number of seconds since midnight is:\r\n"); cprintf("The number of minutes since midnight is:\r\n"); cprintf("The number of hours since midnight is:\r\n"); cprintf("\r\nPress any key to quit:"); while(!kbhit()) { bios_time = biostime(0, 0L); gotoxy(50, 1); cprintf("%lu", bios_time); gotoxy(50, 2); cprintf("%.4f", bios_time / CLK_TCK); gotoxy(50, 3); cprintf("%.4f", bios_time / CLK_TCK / 60); gotoxy(50, 4); cprintf("%.4f", bios_time / CLK_TCK / 3600); } return 0; } 函数名: brk 功 能: 改变数据段空间分配 用 法: int brk(void *endds); 程序例:#include <stdio.h> #include <alloc.h>int main(void) { char *ptr; printf("Changing allocation with brk()\n"); ptr = malloc(1); printf("Before brk() call:%lu bytes free\n",coreleft()); brk(ptr+1000); printf(" After brk() call:%lu bytes free\n",coreleft()); return 0; } 函数名: bsearch 功 能: 二分法搜索 用 法: void *bsearch( const void *key, const void *base, size_t *nelem, size_t width, int(*fcmp)(const void *, const *)); 程序例: #include <stdlib.h> #include <stdio.h> #define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) int numarray[] = {123, 145, 512, 627, 800, 933}; int numeric (const int *p1, const int *p2) { return(*p1 - *p2); }int lookup(int key) { int *itemptr; /* The cast of (int(*)(const void *,const void*)) is needed to avoid a type mismatch error at compile time */ itemptr = bsearch (&key, numarray, NELEMS(numarray), sizeof(int), (int(*)(const void *,const void *))numeric); return (itemptr != NULL);
|