📄 王大刚--c语言编程宝典--d.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/023.htm -->
<HTML><HEAD><TITLE>王大刚-->C语言编程宝典-->D</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大刚 C语言编程宝典 D" name=keywords>
<META content="王大刚 - C语言编程宝典 - D" name=description>
<STYLE>#page {
LEFT: 0px; POSITION: absolute; TOP: 0px
}
.tt3 {
FONT: 9pt/12pt "宋体"
}
.tt2 {
FONT: 12pt/15pt "宋体"
}
A {
TEXT-DECORATION: none
}
A:hover {
COLOR: blue; TEXT-DECORATION: underline
}
</STYLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#006699 aLink=#9900ff link=#006699 bgColor=#ffffff
leftMargin=3 topMargin=3 marginwidth="3" marginheight="3">
<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
<TBODY>
<TR>
<TD class=tt3 vAlign=top width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/024.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/022.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>
<TD class=tt2 width="84%" bgColor=#f5f8f8>
<CENTER><B><FONT style="FONT-SIZE: 16.5pt" face=楷体_GB2312
color=#ff6666>D</FONT></B></CENTER>
<HR width="94%" color=#ee9b73 SIZE=1>
<P>函数名: delay <BR>功 能: 将程序的执行暂停一段时间(毫秒) <BR>用 法: void
delay(unsigned milliseconds); <BR>程序例: <BR>/* Emits a 440-Hz tone for 500
milliseconds */ <BR>#include <dos.h> <BR>
<P>int main(void) <BR>{ <BR> sound(440); <BR>
delay(500); <BR> nosound(); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: delline <BR>功 能: 在文本窗口中删去一行 <BR>用 法: void
delline(void); <BR>程序例: <BR>
<P>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> clrscr(); <BR>
cprintf("The function DELLINE deletes \ <BR> the line
containing the\r\n"); <BR> cprintf("cursor and moves all lines
\ <BR> below it one line up.\r\n"); <BR>
cprintf("DELLINE operates within the \ <BR> currently
active text\r\n"); <BR> cprintf("window. Press any key
to \ <BR> continue . . ."); <BR>
gotoxy(1,2); /* Move the cursor to the
<BR> second line and first column */
<BR> getch(); <BR>
<P> delline(); <BR> getch(); <BR>
<P> return 0; <BR>} <BR> <BR>
<P>函数名: detectgraph <BR>功 能: 通过检测硬件确定图形驱动程序和模式 <BR>用 法: void
far detectgraph(int far *graphdriver, int far *graphmode); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>/* names of the various cards supported */ <BR>char *dname[] = {
"requests detection", <BR> "a CGA",
<BR> "an MCGA", <BR> "an EGA",
<BR> "a 64K EGA", <BR> "a monochrome
EGA", <BR> "an IBM 8514", <BR> "a
Hercules monochrome", <BR> "an AT&T 6300 PC",
<BR> "a VGA", <BR> "an IBM 3270 PC"
<BR> }; <BR>
<P>int main(void) <BR>{ <BR> /* returns detected hardware
info. */ <BR> int gdriver, gmode, errorcode; <BR>
<P> /* detect graphics hardware available */ <BR>
detectgraph(&gdriver, &gmode); <BR>
<P> /* read result of detectgraph call */ <BR>
errorcode = graphresult(); <BR> if (errorcode != grOk)
/* an error <BR> occurred
*/ <BR> { <BR> printf("Graphics
error: %s\n", \ <BR>
grapherrormsg(errorcode)); <BR>
printf("Press any key to halt:"); <BR>
getch(); <BR> exit(1); /* terminate with an
error <BR> code */ <BR> } <BR>
<P> /* display the information detected */ <BR>
clrscr(); <BR> printf("You have %s video display \
<BR> card.\n", dname[gdriver]); <BR> printf("Press
any key to halt:"); <BR> getch(); <BR> return 0;
<BR>} <BR> <BR> <BR> <BR>
<P>函数名: difftime <BR>功 能: 计算两个时刻之间的时间差 <BR>用 法: double
difftime(time_t time2, time_t time1); <BR>程序例: <BR>
<P>#include <time.h> <BR>#include <stdio.h> <BR>#include
<dos.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> time_t first, second; <BR>
<P> clrscr(); <BR> first = time(NULL); /*
Gets system <BR> time */ <BR>
delay(2000); /* Waits 2
secs */ <BR> second = time(NULL); /* Gets system time
<BR> again */ <BR>
<P> printf("The difference is: %f \ <BR>
seconds\n",difftime(second,first)); <BR> getch(); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: disable <BR>功 能: 屏蔽中断 <BR>用 法: void disable(void);
<BR>程序例: <BR>
<P>/***NOTE: This is an interrupt service <BR> routine. You cannot
compile this program <BR> with Test Stack Overflow turned on and
<BR> get an executable file that operates <BR> correctly. */
<BR>
<P>#include <stdio.h> <BR>#include <dos.h> <BR>#include
<conio.h> <BR>
<P>#define INTR 0X1C /* The clock tick <BR>
interrupt */ <BR>
<P>void interrupt ( *oldhandler)(void); <BR>
<P>int count=0; <BR>
<P>void interrupt handler(void) <BR>{ <BR>/* disable interrupts during the
handling of <BR> the interrupt */ <BR> disable();
<BR>/* increase the global counter */ <BR> count++; <BR>/*
reenable interrupts at the end of the <BR> handler */
<BR> enable(); <BR>/* call the old routine */ <BR>
oldhandler(); <BR>} <BR>
<P>int main(void) <BR>{ <BR>/* save the old interrupt vector */
<BR> oldhandler = getvect(INTR); <BR>
<P>/* install the new interrupt handler */ <BR> setvect(INTR,
handler); <BR>
<P>/* loop until the counter exceeds 20 */ <BR> while (count
< 20) <BR> printf("count is %d\n",count);
<BR>
<P>/* reset the old interrupt handler */ <BR> setvect(INTR,
oldhandler); <BR>
<P> return 0; <BR>} <BR>
<P>函数名: div <BR>功 能: 将两个整数相除, 返回商和余数 <BR>用 法: div_t (int
number, int denom); <BR>程序例: <BR>
<P>#include <stdlib.h> <BR>#include <stdio.h> <BR>
<P>div_t x; <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -