王大刚--c语言编程宝典--b.htm
来自「初学者的良师益友。其中包括C的全部教程。」· HTM 代码 · 共 288 行 · 第 1/2 页
HTM
288 行
<BR> DONE = TRUE;
<BR> bioscom(1, in, COM1); <BR> }
<BR> } <BR> return 0; <BR>} <BR> <BR>
<BR> <BR>
<P>函数名: biosdisk <BR>功 能: 软硬盘I/O <BR>用 法: int biosdisk(int
cmd, int drive, int head, int track, int sector
<BR> int nsects, void *buffer);
<BR>程序例: <BR>
<P>#include <bios.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> int result; <BR> char
buffer[512]; <BR>
<P> printf("Testing to see if drive a: is ready\n");
<BR> result = biosdisk(4,0,0,0,0,1,buffer); <BR>
result &= 0x02; <BR> (result) ? (printf("Drive A:
Ready\n")) : <BR> (printf("Drive A:
Not Ready\n")); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: biosequip <BR>功 能: 检查设备 <BR>用 法: int biosequip(void);
<BR>程序例: <BR>
<P>#include <bios.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> int result; <BR> char
buffer[512]; <BR>
<P> printf("Testing to see if drive a: is ready\n");
<BR> result = biosdisk(4,0,0,0,0,1,buffer); <BR>
result &= 0x02; <BR> (result) ? (printf("Drive A:
Ready\n")) : <BR> (printf("Drive A:
Not Ready\n")); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: bioskey <BR>功 能: 直接使用BIOS服务的键盘接口 <BR>用 法: int
bioskey(int cmd); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <bios.h> <BR>#include
<ctype.h> <BR>
<P>#define RIGHT 0x01 <BR>#define LEFT 0x02 <BR>#define
CTRL 0x04 <BR>#define ALT 0x08 <BR>
<P>int main(void) <BR>{ <BR> int key, modifiers; <BR>
<P> /* function 1 returns 0 until a key is pressed */
<BR> while (bioskey(1) == 0); <BR>
<P> /* function 0 returns the key that is waiting */
<BR> key = bioskey(0); <BR>
<P> /* use function 2 to determine if shift keys were used */
<BR> modifiers = bioskey(2); <BR> if (modifiers)
<BR> { <BR> printf("[");
<BR> if (modifiers & RIGHT)
printf("RIGHT"); <BR> if (modifiers &
LEFT) printf("LEFT"); <BR> if
(modifiers & CTRL) printf("CTRL");
<BR> if (modifiers & ALT)
printf("ALT"); <BR> printf("]");
<BR> } <BR> /* print out the character read */
<BR> if (isalnum(key & 0xFF))
<BR> printf("'%c'\n", key); <BR>
else <BR> printf("%#02x\n", key);
<BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: biosmemory <BR>功 能: 返回存储块大小 <BR>用 法:int
biosmemory(void); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <bios.h> <BR>
<P>int main(void) <BR>{ <BR> int memory_size; <BR>
<P> memory_size = biosmemory(); /* returns value up to
640K */ <BR> printf("RAM size = %dK\n",memory_size);
<BR> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: biosprint <BR>功 能: 直接使用BIOS服务的打印机I/O <BR>用 法: int
biosprint(int cmd, int byte, int port); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <conio.h> <BR>#include
<bios.h> <BR>
<P>int main(void) <BR>{ <BR> #define STATUS
2 /* printer status command */ <BR> #define
PORTNUM 0 /* port number for LPT1 */ <BR>
<P> int status, abyte=0; <BR>
<P> printf("Please turn off your printer. Press any key
to continue\n"); <BR> getch(); <BR> status =
biosprint(STATUS, abyte, PORTNUM); <BR> if (status & 0x01)
<BR> printf("Device time out.\n");
<BR> if (status & 0x08) <BR>
printf("I/O error.\n"); <BR>
<P> if (status & 0x10) <BR>
printf("Selected.\n"); <BR> if (status & 0x20)
<BR> printf("Out of paper.\n"); <BR>
<P> if (status & 0x40) <BR>
printf("Acknowledge.\n"); <BR> if (status & 0x80)
<BR> printf("Not busy.\n"); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: biostime <BR>功 能: 读取或设置BIOS时间 <BR>用 法: long
biostime(int cmd, long newtime); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <bios.h> <BR>#include
<time.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> long bios_time; <BR>
<P> clrscr(); <BR> cprintf("The number of clock
ticks since midnight is:\r\n"); <BR> cprintf("The number of
seconds since midnight is:\r\n"); <BR> cprintf("The number of
minutes since midnight is:\r\n"); <BR> cprintf("The number of
hours since midnight is:\r\n"); <BR> cprintf("\r\nPress any
key to quit:"); <BR> while(!kbhit()) <BR> {
<BR> bios_time = biostime(0, 0L); <BR>
<P> gotoxy(50, 1);
<BR> cprintf("%lu", bios_time); <BR>
<P> gotoxy(50, 2);
<BR> cprintf("%.4f", bios_time / CLK_TCK);
<BR>
<P> gotoxy(50, 3);
<BR> cprintf("%.4f", bios_time / CLK_TCK /
60); <BR>
<P> gotoxy(50, 4);
<BR> cprintf("%.4f", bios_time / CLK_TCK /
3600); <BR> } <BR> return 0; <BR>} <BR>
<BR> <BR> <BR>
<P>函数名: brk <BR>功 能: 改变数据段空间分配 <BR>用 法: int brk(void *endds);
<BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <alloc.h> <BR>
<P>int main(void) <BR>{ <BR> char *ptr; <BR>
<P> printf("Changing allocation with brk()\n");
<BR> ptr = malloc(1); <BR> printf("Before brk()
call: %lu bytes free\n", coreleft()); <BR> brk(ptr+1000);
<BR> printf(" After brk() call: %lu bytes free\n",
coreleft()); <BR> return 0; <BR>} <BR> <BR>
<BR> <BR>
<P>函数名: bsearch <BR>功 能: 二分法搜索 <BR>用 法: void *bsearch(const
void *key, const void *base, size_t *nelem,
<BR> size_t width,
int(*fcmp)(const void *, const *)); <BR>程序例: <BR>
<P>#include <stdlib.h> <BR>#include <stdio.h> <BR>
<P>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) <BR>
<P>int numarray[] = {123, 145, 512, 627, 800, 933}; <BR>
<P>int numeric (const int *p1, const int *p2) <BR>{ <BR>
return(*p1 - *p2); <BR>} <BR>
<P>int lookup(int key) <BR>{ <BR> int *itemptr; <BR>
<P> /* The cast of (int(*)(const void *,const void*))
<BR> is needed to avoid a type mismatch
error at <BR> compile time */
<BR> itemptr = bsearch (&key, numarray, NELEMS(numarray),
<BR> sizeof(int), (int(*)(const void *,const
void *))numeric); <BR> return (itemptr != NULL); <BR>} <BR>
<P>int main(void) <BR>{ <BR> if (lookup(512))
<BR> printf("512 is in the table.\n");
<BR> else <BR> printf("512 isn't
in the table.\n"); <BR>
<P> return 0; <BR>} <BR> <BR>
<HR width="94%" color=#ee9b73 SIZE=1>
</TD>
<TD class=tt3 vAlign=bottom width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/022.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/020.htm">前一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD></TR></TBODY></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?