d.txt
Upload User: harvey99
Upload Date: 2020-01-11
Package Size: 938k
Code Size: 8k
Category:

Other Books

Development Platform:

CHM

  1. 函数名: delay           
  2. 功  能: 将程序的执行暂停一段时间(毫秒)
  3. 用  法: void delay(unsigned milliseconds);
  4. 程序例:
  5. /* Emits a 440-Hz tone for 500 milliseconds */
  6. #include <dos.h> 
  7. int main(void)
  8.    sound(440);
  9.    delay(500);
  10.    nosound();
  11.    return 0;
  12. }
  13.  
  14.  
  15. 函数名: delline
  16. 功  能: 在文本窗口中删去一行
  17. 用  法: void delline(void);
  18. 程序例:
  19. #include <conio.h>
  20. int main(void)
  21. {
  22.    clrscr();
  23.    cprintf("The function DELLINE deletes 
  24.     the line containing thern");
  25.    cprintf("cursor and moves all lines 
  26.     below it one line up.rn");
  27.    cprintf("DELLINE operates within the 
  28.     currently active textrn");
  29.    cprintf("window.  Press any key to 
  30.     continue . . .");
  31.    gotoxy(1,2);  /* Move the cursor to the
  32.       second line and first column */
  33.    getch();
  34.    delline();
  35.    getch();
  36.    return 0;
  37. }
  38.  
  39. 函数名: detectgraph
  40. 功  能: 通过检测硬件确定图形驱动程序和模式
  41. 用  法: void far detectgraph(int far *graphdriver, int far *graphmode);
  42. 程序例:
  43. #include <graphics.h>
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. #include <conio.h>
  47. /* names of the various cards supported */
  48. char *dname[] = { "requests detection",
  49.     "a CGA",
  50.     "an MCGA",
  51.     "an EGA",
  52.     "a 64K EGA",
  53.     "a monochrome EGA",
  54.     "an IBM 8514",
  55.     "a Hercules monochrome",
  56.     "an AT&T 6300 PC",
  57.     "a VGA",
  58.     "an IBM 3270 PC"
  59.   };
  60. int main(void)
  61. {
  62.    /* returns detected hardware info. */
  63.    int gdriver, gmode, errorcode;
  64.   /* detect graphics hardware available */
  65.    detectgraph(&gdriver, &gmode);
  66.    /* read result of detectgraph call */
  67.    errorcode = graphresult();
  68.    if (errorcode != grOk)  /* an error
  69.          occurred */
  70.    {
  71.       printf("Graphics error: %sn", 
  72.       grapherrormsg(errorcode));
  73.       printf("Press any key to halt:");
  74.       getch();
  75.       exit(1); /* terminate with an error
  76.     code */
  77.    }
  78.    /* display the information detected */
  79.    clrscr();
  80.    printf("You have %s video display 
  81.    card.n", dname[gdriver]);
  82.    printf("Press any key to halt:");
  83.    getch();
  84.    return 0;
  85. }
  86.  
  87.  
  88.  
  89. 函数名: difftime
  90. 功  能: 计算两个时刻之间的时间差
  91. 用  法: double difftime(time_t time2, time_t time1);
  92. 程序例:
  93. #include <time.h>
  94. #include <stdio.h>
  95. #include <dos.h>
  96. #include <conio.h>
  97. int main(void)
  98. {
  99.    time_t first, second;
  100.    clrscr();
  101.    first = time(NULL);  /* Gets system
  102.       time */
  103.    delay(2000);         /* Waits 2 secs */
  104.    second = time(NULL); /* Gets system time
  105.       again */
  106.    printf("The difference is: %f 
  107.    secondsn",difftime(second,first));
  108.    getch();
  109.    return 0;
  110. }
  111.  
  112.  
  113. 函数名: disable
  114. 功  能: 屏蔽中断
  115. 用  法: void disable(void);
  116. 程序例:
  117. /***NOTE: This is an interrupt service
  118.  routine. You cannot compile this program
  119.  with Test Stack Overflow turned on and
  120.  get an executable file that operates
  121.  correctly. */
  122. #include <stdio.h>
  123. #include <dos.h>
  124. #include <conio.h>
  125. #define INTR 0X1C    /* The clock tick
  126.    interrupt */
  127. void interrupt ( *oldhandler)(void);
  128. int count=0;
  129. void interrupt handler(void)
  130. {
  131. /* disable interrupts during the handling of
  132.    the interrupt */
  133.    disable();
  134. /* increase the global counter */
  135.    count++;
  136. /* reenable interrupts at the end of the
  137.    handler */
  138.    enable();
  139. /* call the old routine */
  140.    oldhandler();
  141. }
  142. int main(void)
  143. {
  144. /* save the old interrupt vector */
  145.    oldhandler = getvect(INTR);
  146. /* install the new interrupt handler */
  147.    setvect(INTR, handler);
  148. /* loop until the counter exceeds 20 */
  149.    while (count < 20)
  150.       printf("count is %dn",count);
  151. /* reset the old interrupt handler */
  152.    setvect(INTR, oldhandler);
  153.    return 0;
  154. }
  155. 函数名: div
  156. 功  能: 将两个整数相除, 返回商和余数
  157. 用  法: div_t (int number, int denom);
  158. 程序例:
  159. #include <stdlib.h>
  160. #include <stdio.h>
  161. div_t x;
  162. int main(void)
  163. {
  164.    x = div(10,3);
  165.    printf("10 div 3 = %d remainder %dn", x.quot, x.rem);
  166.    return 0;
  167. }
  168.  
  169.  
  170. 函数名: dosexterr
  171. 功  能: 获取扩展DOS错误信息
  172. 用  法: int dosexterr(struct DOSERR *dblkp);
  173. 程序例:
  174. #include <stdio.h>
  175. #include <dos.h>
  176. int main(void)
  177. {
  178.    FILE *fp;
  179.    struct DOSERROR info;
  180.    fp = fopen("perror.dat","r");
  181.    if (!fp) perror("Unable to open file for
  182.      reading");
  183.    dosexterr(&info);
  184.    printf("Extended DOS error 
  185.    information:n");
  186.    printf("   Extended error: 
  187.    %dn",info.exterror);
  188.    printf("            Class: 
  189.    %xn",info.class);
  190.    printf("           Action: 
  191.    %xn",info.action);
  192.    printf("      Error Locus: 
  193.    %xn",info.locus);
  194.    return 0;
  195. }
  196.  
  197.  
  198. 函数名: dostounix
  199. 功  能: 转换日期和时间为UNIX时间格式
  200. 用  法: long dostounix(struct date *dateptr, struct time *timeptr);
  201. 程序例:
  202.  #include <time.h>
  203.  #include <stddef.h>
  204.  #include <dos.h>
  205.  #include <stdio.h>
  206.  int main(void)
  207.  {
  208.     time_t t;
  209.     struct time d_time;
  210.     struct date d_date;
  211.     struct tm *local;
  212.     getdate(&d_date);
  213.     gettime(&d_time);
  214.     t = dostounix(&d_date, &d_time);
  215.     local = localtime(&t);
  216.     printf("Time and Date: %sn", 
  217.     asctime(local));
  218.     return 0;
  219. }
  220.  
  221.  
  222. 函数名: drawpoly
  223. 功  能: 画多边形
  224. 用  法: void far drawpoly(int numpoints, int far *polypoints);
  225. 程序例:
  226. #include <graphics.h>
  227. #include <stdlib.h>
  228. #include <stdio.h>
  229. #include <conio.h>
  230. int main(void)
  231. {
  232.    /* request auto detection */
  233.    int gdriver = DETECT, gmode, errorcode;
  234.    int maxx, maxy;
  235.    /* our polygon array */
  236.    int poly[10];
  237.    /* initialize graphics and local
  238.       variables */
  239.    initgraph(&gdriver, &gmode, "");
  240.    /* read result of initialization */
  241.    errorcode = graphresult();
  242.    if (errorcode != grOk)
  243.    /* an error occurred */
  244.    {
  245.       printf("Graphics error: %sn", 
  246.       grapherrormsg(errorcode));
  247.       printf("Press any key to halt:");
  248.       getch();
  249.    /* terminate with an error code */
  250.       exit(1);
  251.    }
  252.    maxx = getmaxx();
  253.    maxy = getmaxy();
  254.    poly[0] = 20;        /* 1st vertext */
  255.    poly[1] = maxy / 2;
  256.    poly[2] = maxx - 20; /* 2nd */
  257.    poly[3] = 20;
  258.    poly[4] = maxx - 50; /* 3rd */
  259.    poly[5] = maxy - 20;
  260.    poly[6] = maxx / 2;  /* 4th */
  261.    poly[7] = maxy / 2;
  262. /*
  263.    drawpoly doesn't automatically close
  264.    the polygon, so we close it.
  265. */
  266.    poly[8] = poly[0];
  267.    poly[9] = poly[1];
  268.    /* draw the polygon */
  269.    drawpoly(5, poly);
  270.    /* clean up */
  271.    getch();
  272.    closegraph();
  273.    return 0;
  274. }
  275.  
  276.  
  277. 函数名: dup
  278. 功  能: 复制一个文件句柄
  279. 用  法: int dup(int handle);
  280. 程序例:
  281. #include <string.h>
  282. #include <stdio.h>
  283. #include <conio.h>
  284. #include <io.h>
  285. void flush(FILE *stream);
  286. int main(void)
  287. {
  288.    FILE *fp;
  289.    char msg[] = "This is a test";
  290.    /* create a file */
  291.    fp = fopen("DUMMY.FIL", "w");
  292.    /* write some data to the file */
  293.    fwrite(msg, strlen(msg), 1, fp);
  294.    clrscr();
  295.    printf("Press any key to flush 
  296.    DUMMY.FIL:");
  297.    getch();
  298.    /* flush the data to DUMMY.FIL without
  299.       closing it */
  300.    flush(fp);
  301.    printf("nFile was flushed, Press any 
  302.    key to quit:");
  303.    getch();
  304.    return 0;
  305. }
  306. void flush(FILE *stream)
  307. {
  308.    int duphandle;
  309.    /* flush TC's internal buffer */
  310.    fflush(stream);
  311.    /* make a duplicate file handle */
  312.    duphandle = dup(fileno(stream));
  313.    /* close the duplicate handle to flush the
  314.       DOS buffer */
  315.    close(duphandle);
  316. }
  317.  
  318.  
  319. 函数名: dup2
  320. 功  能: 复制文件句柄
  321. 用  法: int dup2(int oldhandle, int newhandle);
  322. 程序例:
  323. #include <sysstat.h>
  324. #include <string.h>
  325. #include <fcntl.h>
  326. #include <io.h>
  327. int main(void)
  328. {
  329.    #define STDOUT 1
  330.    int nul, oldstdout;
  331.    char msg[] = "This is a test";
  332.    /* create a file */
  333.    nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
  334.       S_IREAD | S_IWRITE);
  335.    /* create a duplicate handle for standard
  336.       output */
  337.    oldstdout = dup(STDOUT);
  338.    /*
  339.       redirect standard output to DUMMY.FIL
  340.       by duplicating the file handle onto the
  341.       file handle for standard output.
  342.    */
  343.    dup2(nul, STDOUT);
  344.    /* close the handle for DUMMY.FIL */
  345.    close(nul);
  346.    /* will be redirected into DUMMY.FIL */
  347.    write(STDOUT, msg, strlen(msg));
  348.    /* restore original standard output
  349.       handle */
  350.    dup2(oldstdout, STDOUT);
  351.    /* close duplicate handle for STDOUT */
  352.    close(oldstdout);
  353.    return 0;
  354. }