📄 fd.htm
字号:
<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>fd</TITLE></HEAD><BODY> <P>函数名: delay<BR>功 能: 将程序的执行暂停一段时间(毫秒)<BR>用 法: void delay(unsigned milliseconds);<BR>程序例:<BR>/* Emits a 440-Hz tone for 500 milliseconds */<BR>#include <dos.h><P>int main(void)<BR>{<BR> sound(440);<BR> delay(500);<BR> nosound();<P> return 0;<BR>}<BR> <BR> <P>函数名: delline<BR>功 能: 在文本窗口中删去一行<BR>用 法: void delline(void);<BR>程序例:<P>#include <conio.h><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();<P> delline();<BR> getch();<P> return 0;<BR>}<BR> <P>函数名: detectgraph<BR>功 能: 通过检测硬件确定图形驱动程序和模式<BR>用 法: void far detectgraph(int far *graphdriver, int far *graphmode);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><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> };<P>int main(void)<BR>{<BR> /* returns detected hardware info. */<BR> int gdriver, gmode, errorcode;<P> /* detect graphics hardware available */<BR> detectgraph(&gdriver, &gmode);<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> }<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> <P>函数名: difftime<BR>功 能: 计算两个时刻之间的时间差<BR>用 法: double difftime(time_t time2, time_t time1);<BR>程序例:<P>#include <time.h><BR>#include <stdio.h><BR>#include <dos.h><BR>#include <conio.h><P>int main(void)<BR>{<BR> time_t first, second;<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 */<P> printf("The difference is: %f \<BR> seconds\n",difftime(second,first));<BR> getch();<P> return 0;<BR>}<BR> <BR> <P>函数名: disable<BR>功 能: 屏蔽中断<BR>用 法: void disable(void);<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. */<P>#include <stdio.h><BR>#include <dos.h><BR>#include <conio.h><P>#define INTR 0X1C /* The clock tick<BR> interrupt */<P>void interrupt ( *oldhandler)(void);<P>int count=0;<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>}<P>int main(void)<BR>{<BR>/* save the old interrupt vector */<BR> oldhandler = getvect(INTR);<P>/* install the new interrupt handler */<BR> setvect(INTR, handler);<P>/* loop until the counter exceeds 20 */<BR> while (count < 20)<BR> printf("count is %d\n",count);<P>/* reset the old interrupt handler */<BR> setvect(INTR, oldhandler);<P> return 0;<BR>}<P>函数名: div<BR>功 能: 将两个整数相除, 返回商和余数<BR>用 法: div_t (int number, int denom);<BR>程序例:<P>#include <stdlib.h><BR>#include <stdio.h><P>div_t x;<P>int main(void)<BR>{<BR> x = div(10,3);<BR> printf("10 div 3 = %d remainder %d\n", x.quot, x.rem);<P> return 0;<BR>}<BR> <BR> <P>函数名: dosexterr<BR>功 能: 获取扩展DOS错误信息<BR>用 法: int dosexterr(struct DOSERR *dblkp);<BR>程序例:<P>#include <stdio.h><BR>#include <dos.h><P>int main(void)<BR>{<BR> FILE *fp;<BR> struct DOSERROR info;<P> fp = fopen("perror.dat","r");<BR> if (!fp) perror("Unable to open file for<BR> reading");<BR> dosexterr(&info);<P> printf("Extended DOS error \<BR> information:\n");<BR> printf(" Extended error: \<BR> %d\n",info.exterror);<BR> printf(" Class: \<BR> %x\n",info.class);<BR> printf(" Action: \<BR> %x\n",info.action);<BR> printf(" Error Locus: \<BR> %x\n",info.locus);<P> return 0;<BR>}<BR> <BR> <P>函数名: dostounix<BR>功 能: 转换日期和时间为UNIX时间格式<BR>用 法: long dostounix(struct date *dateptr, struct time *timeptr);<BR>程序例:<P> #include <time.h><BR> #include <stddef.h><BR> #include <dos.h><BR> #include <stdio.h><P> int main(void)<BR> {<BR> time_t t;<BR> struct time d_time;<BR> struct date d_date;<BR> struct tm *local;<P> getdate(&d_date);<BR> gettime(&d_time);<P> t = dostounix(&d_date, &d_time);<BR> local = localtime(&t);<BR> printf("Time and Date: %s\n", \<BR> asctime(local));<P> return 0;<BR>}<BR> <BR> <P>函数名: drawpoly<BR>功 能: 画多边形<BR>用 法: void far drawpoly(int numpoints, int far *polypoints);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>int main(void)<BR>{<BR> /* request auto detection */<BR> int gdriver = DETECT, gmode, errorcode;<BR> int maxx, maxy;<P> /* our polygon array */<BR> int poly[10];<P> /* initialize graphics and local<BR> variables */<BR> initgraph(&gdriver, &gmode, "");<P> /* read result of initialization */<BR> errorcode = graphresult();<BR> if (errorcode != grOk)<BR> /* an error occurred */<BR> {<BR> printf("Graphics error: %s\n", \<BR> grapherrormsg(errorcode));<BR> printf("Press any key to halt:");<BR> getch();<BR> /* terminate with an error code */<BR> exit(1);<BR> }<P> maxx = getmaxx();<BR> maxy = getmaxy();<P> poly[0] = 20; /* 1st vertext */<BR> poly[1] = maxy / 2;<P> poly[2] = maxx - 20; /* 2nd */<BR> poly[3] = 20;<P> poly[4] = maxx - 50; /* 3rd */<BR> poly[5] = maxy - 20;<P> poly[6] = maxx / 2; /* 4th */<BR> poly[7] = maxy / 2;<BR>/*<BR> drawpoly doesn't automatically close<BR> the polygon, so we close it.<BR>*/<BR> poly[8] = poly[0];<BR> poly[9] = poly[1];<P> /* draw the polygon */<BR> drawpoly(5, poly);<P> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <P>函数名: dup<BR>功 能: 复制一个文件句柄<BR>用 法: int dup(int handle);<BR>程序例:<P>#include <string.h><BR>#include <stdio.h><BR>#include <conio.h><BR>#include <io.h><P>void flush(FILE *stream);<P>int main(void)<BR>{<BR> FILE *fp;<BR> char msg[] = "This is a test";<P> /* create a file */<BR> fp = fopen("DUMMY.FIL", "w");<P> /* write some data to the file */<BR> fwrite(msg, strlen(msg), 1, fp);<P> clrscr();<BR> printf("Press any key to flush \<BR> DUMMY.FIL:");<BR> getch();<P> /* flush the data to DUMMY.FIL without<BR> closing it */<BR> flush(fp);<P> printf("\nFile was flushed, Press any \<BR> key to quit:");<BR> getch();<BR> return 0;<BR>}<P>void flush(FILE *stream)<BR>{<BR> int duphandle;<P> /* flush TC's internal buffer */<BR> fflush(stream);<P> /* make a duplicate file handle */<BR> duphandle = dup(fileno(stream));<P> /* close the duplicate handle to flush the<BR> DOS buffer */<BR> close(duphandle);<BR>}<BR> <BR> <P>函数名: dup2<BR>功 能: 复制文件句柄<BR>用 法: int dup2(int oldhandle, int newhandle);<BR>程序例:<P>#include <sys\stat.h><BR>#include <string.h><BR>#include <fcntl.h><BR>#include <io.h><P>int main(void)<BR>{<BR> #define STDOUT 1<P> int nul, oldstdout;<BR> char msg[] = "This is a test";<P> /* create a file */<BR> nul = open("DUMMY.FIL", O_CREAT | O_RDWR,<BR> S_IREAD | S_IWRITE);<P> /* create a duplicate handle for standard<BR> output */<BR> oldstdout = dup(STDOUT);<BR> /*<BR> redirect standard output to DUMMY.FIL<BR> by duplicating the file handle ontothe<BR> file handle for standard output.<BR> */<BR> dup2(nul, STDOUT);<P> /* close the handle for DUMMY.FIL */<BR> close(nul);<P> /* will be redirected into DUMMY.FIL */<BR> write(STDOUT, msg, strlen(msg));<P> /* restore original standard output<BR> handle */<BR> dup2(oldstdout, STDOUT);<P> /* close duplicate handle for STDOUT */<BR> close(oldstdout);<P> return 0;<BR>}<BR> <P> <A HREF="index.html">返回目录</A><BR> <BR> <BR> <BR> <BR> </BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -